Hi all, i have this assigment, my program has to read in scores from judges, calculate avaryge and put out a winner. i got that working fine but as well as putting out the highest score i have to put out the name of the winner and unfortunatly my program always puts out the last name, not the name of the acctual winner. PLZ help, its driving me crazy.
ps. I changed it to a string winner = name but it puts out nothing
That means you need something else like a small class or a struct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
struct celebrity
{
string name ;
float score;
}
celebrity mycel;
std::vector <celebrity> celebvector; /// will hold all celebrities details
for (size_t i=0; i <numCeleb; i++)
{
cout <<"enter name of celebrity "<<i <<" and their score from judges :";
cin>> mycel.name>> mycel. score;
/// more code here
celebvector.push_back (mycel);// you can get celebrity name from vector later
}
Okay that a condition I added which intializes max2 /*and*/ name to the results of the first contestant . It takes care of the possibility of having only on contestant in the game and by intializing our variables to the results of the first person we are guaranteed to have a winner at the end and those can only be changed at line 49 if there is any other contestant with scores higher than the current score.