| | |
counting a few numbers and storing the values
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 22
Reputation:
Solved Threads: 0
Hello, i am trying to count from 0 - 7 and storing the values in an array.
I have been trying to do this solidly for 2 weeks
my attempt:
**************************************
int a[20];
int x;
for ( x=0 ; x<=7 ; x++ ) {
a[1] = x;
cout << x << endl; }
***************************************
I know that the output from this program is correct, i.e. it displays:
0
1
2
.
.
7
my problem is a[1] will only display the value inside the for loop's {}. I want to use an array element, a[1] outside of the for { } with those values stored in there. Please help!
Thanks,
John
I have been trying to do this solidly for 2 weeks
my attempt:
**************************************
int a[20];
int x;
for ( x=0 ; x<=7 ; x++ ) {
a[1] = x;
cout << x << endl; }
***************************************
I know that the output from this program is correct, i.e. it displays:
0
1
2
.
.
7
my problem is a[1] will only display the value inside the for loop's {}. I want to use an array element, a[1] outside of the for { } with those values stored in there. Please help!
Thanks,
John
Last edited by johnnyjohn20; Nov 22nd, 2007 at 3:59 pm. Reason: inserted wrong code
•
•
Join Date: Nov 2007
Posts: 22
Reputation:
Solved Threads: 0
Thank you for your help, so far i have adjusted the code and can now display the values outside of the { }, using
cout << a[1] << endl;
cout << a[2] << endl; ...etc etc. Is there a way i can display all of the values in the array using one simple command?.
Thanks for your time reading my posts!
cout << a[1] << endl;
cout << a[2] << endl; ...etc etc. Is there a way i can display all of the values in the array using one simple command?.
Thanks for your time reading my posts!
Last edited by johnnyjohn20; Nov 22nd, 2007 at 4:47 pm.
![]() |
Similar Threads
- Projects for the Beginner (Python)
- Open In New Window Php (PHP)
- Code not adding my numbers correctly... (C++)
- auto completion of the text box from previous entered values (JavaScript / DHTML / AJAX)
- Random Numbers Help (C++)
- Using two vectors? (C++)
- File input. (C++)
- On The Fly Edit (PHP)
- newbie-How to multipe InputBoxes (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: C++ graphics
- Next Thread: strtoul() function use
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






