-
but if i didn't change it...then it started counting at 0 and ended at 19...i need it to count from 1 to 20..? What do you mean by end of the loop block? I thought you meant, move the x++ to the bottom. I'm sorry...i'm a true newbie...thanks for the help..
-
when you store information in arrays you can go from 1-20, but c++ stores it as 0-19 within the array.
-
I did mean to move x++ to the bottom, but that's all you needed to do. You didn't need to change the other stuff.
Your first attempt at the while loop used indexes 1-20. That is wrong. Your second attempt also uses indexes 1-20, again wrong. The proper indexes for a 20 element array are 0-19. If you take your original while loop attempt, and just move the x++ to the bottom, then it will use 0-19, which is correct.
Follow the flow of each version in you head. Write down the value of x every time you reach the array[x] = x; part. Because you use x as an array index, it must be 0-19.
If you want the values stored by the array to be 1-20, that is ok, but you need either a different variable for the index, or you need to add 1 to the index: array[x] = x+1; The key is that the index must go from 0-19, and you can do whatever you want to get the proper value.
-