+ 2

How to fix this code? int and string x >= items;. I do not know how to fix it.

// Lists items for sale and their prices using System; class DebugSix01 { static void Main() { string[] items = {"Belt", "Tie", "Scarf", "Cufflinks"}; double[] prices = {29.00, 35.95, 18.50, 112.99}; Console.WriteLine("Items for sale:"); for(int x = 0; x >= items; --x) Console.WriteLine("{0,12} for {1,10}}", items[x], prices[x].ToString("C")); } }

27th Sep 2017, 9:55 PM
Abdul Hamid Durrani
Abdul Hamid Durrani - avatar
2 Answers
+ 10
for(int x = 0; x < items.Length; x++) { Console.WriteLine("{0} for {1}", items[x], prices[x]); }
28th Sep 2017, 12:07 AM
Vukan
Vukan - avatar
+ 7
PROBLEM 1 The program have an incorrect for loop setup as you need to loop from the 1st element(index: 0) up to the last item(index: array length - 1) incrementally, so the following setup will do the job: for (int i = 0; i < items.length; i++) or for (int i = 0; i <= items.length - 1; i++) PROBLEM 2 The program 2nd output have an incorrect format and here's the proper way to write it: Console.WriteLine("{0, 12} for {1, 10}", items[x], prices[x].ToString("C"));
28th Sep 2017, 4:19 AM
Zephyr Koo
Zephyr Koo - avatar