Using a flag-Controlled while loop to determine who has the most points

I have a homework assignment where I to read in from a data file a list of names with an integer under each.I have to use a boolean to end the loop once the string "End" has been reached, and determine who is the winner based on whom has the most points. I have to echo out the names, and the name of the winner as well as the points for each name, and the points accumulated.

The list looks like this:
First Last
123
First Last
124
First Last
125
etc..


This is as far as I've gotten.

int mostPoints;
int mostHumourPoints;
int totalHumourPoints;

bool moreComedians;

string comedianName;

//Initialize most points to 0
mostPoints = 0;

//Initialize most humor points
mostHumourPoints = 0;

//Initialize total humor points
totalHumourPoints = 0;

//Initialize more comedians to true
moreComedians = true;

while (moreComedians)
{
getline(fin, comedianName);

if (comedianName == "End")
{
moreComedians = false;

}

else
{
fin >> humorPoints;
humorPoints++;
}

Last edited on
things like:
mostPoints = 0;
will need to be:
int mostPoints = 0;

when you've read in your line you could use something like:

- create an int called linenumber and increment each time you call getLine() in your while.
then.
1
2
3
4
5
6
7
8
if(lineNumber%2==0)
{
// you have an even number therefore we now know it's a number to read in.
}
else
{
// you have an odd number line number so we know you have to read in a "first last" string.
}
Last edited on
Topic archived. No new replies allowed.