c++ printing high index student list

Ok, so I'm trying to print a record that contains the following for a list of graduate students: name, faculty (1 to 5), index, sex. I'm able to list the graduate students with a loop, but can't print the students with an index greater than 1.5. Well, it can, but I want it print the students who did get a high index and not just one. plz help

#include <iostream>

using namespace std;

int main ()
{
string name, gender, faculty_name;
float index;
int i, num, faculty, highscore;

cout << "Enter the number of students for list: ";
cin >> num;

for( i = 0; i < num; ++i )
{
cout<< i + 1 << ". Enter student name: ";
cin>> name;

if (faculty<=5)
{
cout<< i + 1 << ". Enter faculty: ";
cin>> faculty;
}

cout<< i + 1 << ". Enter index: ";
cin>> index;

cout<< i + 1 << ". Enter gender: ";
cin>> gender;

index = highscore;
}

cout<<"List of high index students: " <<endl;
for(i = 0; i < highscore; ++i)
{
if (index >= 1.5)
{
cout<< name << endl;
cout<< faculty << endl;
cout<< gender;
}
}


return 0;
}
How many times will this loop repeat?
for(i = 0; i < highscore; ++i)
Was it supposed to repeat as many times as there are students?


Where have you stored the data of each student?


PS. Please sue code tags when posting code.
Sorry, I'm new at this.

So it repeats the number of students entered. Like if I want a list of two students, it will allow me to type the info of the number of students entered.

I'm not sure about the data.

Plz tell me how to use code tags. thank you
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/
PS. Please sue code tags when posting code.

don't sue the code tags, they're innocent :(
Topic archived. No new replies allowed.