|
-
May 30th, 2009, 05:32 AM
#1
Array problem
Hi,
I am learning to program in C++ and have been learning arrays. In the following piece of code I am wanting to fill an array with the values 100-109. myarray[1] = 100, myarray[2] = 101 and so on. However, when this code is executed, b is actually taking on the values 100 - 109. What have I done wrong here.
thanks
#include <iostream>
using namespace std;
int main()
{
int b, c = 100;
int myarray [10];
for (b =0 ; b<=9; b++) {
myarray [b] = c; // want b to have value 0-9 and be filled with value 100-109.
c++;
cout << "myarray [" << myarray [b] << "] = " << c << "\n";
}
system("pause");
return 0;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|