Discerning highest number from text file

Hello,

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>

using namespace 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;
}
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
string highest;
int max;
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;

inFile >> highest >> max;
totalbox = totalbox + max;
numvolunteer++;
cout << highest << " " << max << endl;

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;




system ("Pause");

return 0;
}
Topic archived. No new replies allowed.