Jump to content

I am trying to take user inputs and store it them in two different arrays using C#


G+_Denzel Brown
 Share

Recommended Posts

I am trying to take user inputs and store it them in two different arrays using C#.  I think that I have everything ready to go but i am getting errors stating that cannot convert a double to an int, and that my local variable i cannot be used in this context because it will change the parent or current scope.  Here is my code //fill arrays

            for (double i = 0; i < chevy.Length; i++)

 

            {

                //enter chevy array

                chevy = Convert.ToInt32(Console.ReadLine());

 

                for (double i = 0; i < ford.Length; i++)

                {

                    //enter ford array 

                    ford = Convert.ToInt32(Console.ReadLine());

                }

                //end fill array

Link to comment
Share on other sites

Typically for loops iterate over ints (i.e. whole numbers), not doubles (which contain fractions). It wouldn't make much sense to ask for the 3rd and a half value in the array - that's what the first error is about. Change it to for (int i = 0;

 

Also you have a for loop inside a for loop. And both are using i as the variable to iterate over. That's a problem as i means two different things - that's basically what the second error is saying. I'd call them i and j.

Link to comment
Share on other sites

 Share

×
×
  • Create New...