i need to know how to make a program print the whole array out
i need to know how to make a program print the whole array out
That's all it takes.Code:int array[5] = { 5,10,15, 20, 25 }; for (int i=0; i<5; i++) cout << "array[" << i << "]: " << array[i] << endl;
Brendan
can you or someone else explain how that works please
Hooked On Phonics Didn't Work For Me!
The array has 5 places.
The loop, is controlled by the integer i.
Normally, with a loopThis would print the string, Message, 10 times in a row.Code:#include <iostream> using namespace std; int main ( void ) { int i; for ( i = 0; i < 10; i++ ) { cout << "Message " <<endl; } return 0; }
The following code, shows that you can change, or add to the string Message, each time you loop it (providing usefulness).That is what harryp's code is doing.Code:#include <iostream> using namespace std; int main ( void ) { int i; for ( i = 0; i < 10; i++ ) { cout << "Message " << i <<endl; } return 0; }
He created a loop, and it will loop 5 times.
It just happens to be that each time it loops, it will print, to the screen, the next chunk of information in the array.
The world is waiting. I must leave you now.