I am trying to decipher from a text file who sold the most boxes. I am able to print to the screen the individual volunteers and the boxes they sold. My code is below. How would I go about doing this? Also, can I get an explanation of the code you provide as well so I can better understand? (Please disregard the System pause syntax at the bottom. I'm just testing the code out)
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
usingnamespace std;
int main()
{
string name;
double cost;
int boxes;
int numvolunteer;
int totalbox;
totalbox = 0;
numvolunteer = 0;
cout << fixed << showpoint;
cout << setprecision(2);
ifstream inFile;
inFile.open("Data.txt");
cout << "What is the cost of each box? ";
cin >> cost;
cout << endl;
while (!inFile.eof())
{
inFile >> name >> boxes;
totalbox = totalbox + boxes;
numvolunteer++;
cout << name << " " << boxes << endl;
}
cout << "The number of boxes sold is: " << totalbox << endl;
cout << "The cost of each box sold is: " << cost << endl;
cout << "The number of volunteers is: " << numvolunteer << endl;
system ("Pause");
return 0;
}
while (!inFile.eof())
{
inFile >> name >> boxes;
if(boxes > max){
max = boxes;
highest = name;
}
totalbox = totalbox + boxes;
numvolunteer++;
cout << name << " " << boxes << endl;
}
cout << "The number of boxes sold is: " << totalbox << endl;
cout << "The cost of each box sold is: " << cost << endl;
cout << "The number of volunteers is: " << numvolunteer << endl;
cout << "The volunteer who sold the most boxes is: << highest << endl;