Write a program using sentinel loop that gets the unspecified number of student names and and then 3 exam scores of each students and calculates the average.
using namespace std;
cout<< "Enter the names or enter No to stop"<< endl;
getline (cin, studentNames);
total = 0;
for (int score=1; score<=3; score++)
double testScore ;
cout << "Enter score " << score << " for ";
cout << "student " << studentNames << ": ";
cin >> testScore;
total += testScore;
}while ( studentNames!=sentinel);
my problem is how to make the user enter the student name again after entering three scores? i need help on that only.
You're very close. You actually are getting the student name each time, but the program is skipping over it because of a cin buffering issue. This happens when you mix getline with 'cin >>' commands.
To fix, throw a
cin.sync(); before the getline call.
thnks for the reply , disch. But cin.sync didnt work.