How to use code tags:
http://www.cplusplus.com/articles/jEywvCM9/
How many times will this loop repeat?
for ( i = 0; i < highscore; ++i ) |
* The 'i' is initialized to 0 at start.
* The loop body will execute IF
i < highscore
* After loop body the 'i' increments by 1
* The loop condition is tested again, ...
=> The 'i' will go through values 0, 1, 2, ... highscore-1
When i==highscore, the i < highscore becomes false, and the loop will end.
There are exactly highscore values in {0, 1, .. highscore-1}.
In other words, that loop repeats
highscore times.
Is the highscore the
number of students?
1 2 3 4 5
|
string name;
for( i = 0; i < num; ++i )
{
cin >> name;
}
|
The loop reads a value into 'name' for 'num' times.
Each read
overwrites the previous value.
After the loop the 'name' holds the value from the
last iteration.
You should store multiple names. The proper way would be to define a
struct that holds data of one student and store structs in a container, like
std::vector
.
http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/reference/vector/vector/emplace_back/