C++ CIN cin skips randomly
- by user69514
I have this program, but cin in randomly skips.. I mean sometimes it does, and sometimes it doesn't. Any ideas how to fix this?
int main(){
/** get course name, number of students, and assignment name **/
string course_name;
int numb_students;
string assignment_name;
Assignment* assignment;
cout << "Enter the name of the course" << endl;
cin >> course_name;
cout << "Enter the number of students" << endl;
cin >> numb_students;
cout << "Enter the name of the assignment" << endl;
cin >> assignment_name;
assignment = new Assignment(assignment_name);
/** iterate asking for student name and score **/
int i = 0;
string student_name;
double student_score = 0.0;
while( i < numb_students ){
cout << "Enter the name for student #" << i << endl;
cin >> student_name;
cout << "Enter the score for student #" << i << endl;
cin >> student_score;
assignment->addScore( Student( student_name, student_score ));
i++;
}
}