Your updated code still skips over one a set number of your input buffers(meaning, if you're the user, and you type 2 characters or integers, you're going to skip over 2 input buffers). Try adding cin.ignore after line 35
#include<iostream>
#include<iomanip>
#include<cmath>
usingnamespace std;
int main (){
staticdouble score;
staticdouble epsilon(0.000001);
staticdouble allowedShift(10.0);
unsignedshort numJudges, numCeleb;
float addScore, finalScore = 0, min, max, max2=0;
string name, winner;
do {
cout << "\n\n\tEnter number of judges: ";
cin >> numJudges;
if (numJudges < 3 || numJudges > 6)
cout << "\n\n\tERROR! Number of judges must be between 3 and 6" << endl;
}
while (numJudges < 3 || numJudges > 6);
do {
cout << "\n\n\tEnter number of paricipants: ";
cin >> numCeleb;
if (numCeleb < 10 || numCeleb > 15)
cout << "\n\n\tERROR! Number of participants must be between 10 and 15" << endl;
}
while (numCeleb < 10 || numCeleb > 15);
for (unsignedshort i = 1; i <= numCeleb; i++){
bool test;
do {
test = true;
cout << "\n\n\tEnter name of celebrity " << i << " : ";
cin.ignore();
getline (cin >> ws, name);
for (unsignedshort n = 0; n < name.length(); n++){
if(!(isdigit(name.at(n)) || isalpha(name.at(n))))
test = false;
}
if (!test)
cout << "\n\n\tERROR! Name can consist of letters and numbers only.\n";
}
while (!test);
addScore = 0,
min = 6,
max = 0;
for (unsignedshort a = 1; a <= numJudges; a++){
do {
cout << "\n\n\tEnter score from judge number " << a << " : ";
cin >> score;
if (score < 0 || score > 6)
cout << "\n\n\tERROR! Score must be between 0 and 6." << endl;
elseif (fabs(trunc(score * allowedShift) - score * allowedShift) > epsilon)
cout << "\n\n\tERROR! Score can have only one deciamal place" << endl;
}
while (fabs(trunc(score * allowedShift) - score * allowedShift) > epsilon);
if (score > max)
max = score;
if (score < min)
min = score;
addScore+=score;
}
finalScore = (addScore - max - min) / (numJudges - 2);
if (i==1){
max2=finalScore;
winner=name;
}
elseif(max2<finalScore){
max2=finalScore;
winner=name;
}
cout << "\n\n\tFinal score is " << finalScore << endl;
}
cout << setw(51) << "And the winner is\n\n" << setw((80+winner.length())/2) << winner << "\n\n"<< setw(42) << max2 << endl;
return 0;
}