Hey Fred and welcome to the forum.
Every function ends the moment it hits a
return
statement. Therefore, I imagine your code only prints out the very first element of the array before it terminates. To fix your problem, simply remove the
return 0;
statement that is currently contained inside of the for-loop.
Also, to keep your CMD open during code execution, add the following right under Line 15:
1 2
|
int temp;
cin >> temp;
|
EDIT: Oh, I just spotted another mistake in your loop. So, the for loop lets you repeat a section of code multiple times (depending on the condition), and it is particularly suited for counting and moving through a sequence of things (like arrays). Your loop initialization and action are valid. However, your condition is incorrect.