G+_LeMar Longhurst Posted October 31, 2014 Share Posted October 31, 2014 That would be because the "Double" has a lot more digits to the right of the int types out rill need to use some sort of round function to remove the extra stuff Originally shared by Denzel Brown 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 More sharing options...
G+_S??u???o S?s??? Posted November 14, 2014 Share Posted November 14, 2014 The loop index i being double (from where it says "for(double i...") and it's use to select element chevy and ford seems to be the problem. You could (1) change the loop index to type int (so "for(int i...)" instead) or (2) you could try converting the type of I to int when you select the element from array chevy and from array ford (so something like "chevy[Convert.Int32(i)]") I would choose (1) because I don't see the necessity of variable i being type double in the for loops of your sample code. What do you think? Link to comment Share on other sites More sharing options...
Recommended Posts