ifile

I'm doing a project and I'm kind of stuck. The text file prog3a.txt is a file like this:
4
MBanner 35 35 35 35 35 35 35 35 34 35 35 35 36
BHunter 40 20 40 70 35 45 78 34 56 73 15 41 55
GJorgensen 60 62 47 68 40 53 62 88 18 15 72 12 19
TSmith 25 66 32 41 89 27 25 29 33 54 27 32 45

number of salesmen
name, quota, 12 months sales

and i need to:
- read in the number of salespeople
- read in the quota for that salesperson
- read in 12 actual monthly sales counts for that salesperson
- determine number of months the salesperson did or did not meet quota
- decide whether a campaign should be mounted
- identify the worst salesperson for meeting quotas

I know the text formatting is off too but I can worry about that after I find out what I'm doing wrong. Help with how to input data from the file correctly would be appreciated, anything else i can figure out on my own


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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <conio.h>

using namespace std;

int main()
{
	int totSalesperson;
	int quota;
	int salesCount;
	int monthsMissed;
	int quotasMissed;
	int monthQuota;
	int months;
	int worst;
	string salesPerson;
	string worstSalesperson;

	const int MAX_FAIL = 20;

	ifstream ifile("prog3a.txt");
	
	if(!ifile)
	{
		cout<< "Can't find source file";
		_getch();
		return 1;
	}

	ifile >> totSalesperson;
	cout << "Total number of salesPeople: " << totSalesperson << endl;

	cout << endl << "Salesman\t\tQuota\tMonthly Sales" << endl;

	for (salesCount = 0; salesCount < totSalesperson; ++salesCount)
	{
		ifile >> salesPerson >> quota >> months;

		cout << endl << salesPerson;

		cout << quota << "\t" << months << monthsMissed << monthQuota;
		monthsMissed = 0;
		worst = 0;

		if (months < quota)
		{
			monthsMissed = monthsMissed + 1;
		}

		cout << months;
		cout << monthsMissed;
		monthQuota = 12 - monthsMissed;

		if (monthsMissed > 0)
		{
			quotasMissed = quotasMissed + 1;
		}

		if (monthsMissed > worst)
		{
			salesPerson = worstSalesperson;
			quotasMissed = worst;
		}

	}

	if ((quotasMissed * 100 / totSalesperson) > MAX_FAIL)
		{
			cout << "Sales campaign should be mounted";
		}
		else;
			cout << "Good work";
		
		cout << "Consider firing: " << worstSalesperson << "\n Program complete!";


	_getch();
	return 0;
}

Here is an example of inputting data

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
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	const int NUMSALES = 12;
	int sales[NUMSALES];
	int quotaMissed = 0;
	int quotaReached = 0;
	int totSalesperson;
	int quota;
	int i = 0;
	string filename = "prog3a.txt";
	string salesPerson;

	ifstream ifile;
	ifile.open(filename);

	if(ifile.fail())
	{
		cout << "File " << filename << " failed to open";
		cin.ignore(100, '\n');
		return 1;
	}

	ifile >> totSalesperson;
	cout << "Total number of salesPeople: " << totSalesperson << endl;

	for (int count = 0; count < totSalesperson; count++)
	{
	
		//input salesPerson and quota
		ifile >> salesPerson >> quota;
		cout << endl << salesPerson;
		
		//input sales
		for(i = 0; i < NUMSALES; i++)
			ifile >> sales[i];

		// count the number of months the salesperson reached his quota
		for(i = 0; i < NUMSALES; i++)
		{
			if(sales[i] < quota)
				quotaMissed++;
			else
				quotaReached++;
		}

		cout << "\nThe number of months " << salesPerson << " reached his quota is " << quotaReached << endl;
		cout << "The number of months " << salesPerson << " missed his quota is " << quotaMissed << endl;
		quotaReached = 0;
		quotaMissed = 0;
	
	}
	cin.ignore(100, '\n');
	return 0;
}
Thanks that helped. The main thing was the output should be like this:
Salesperson Quota Monthly Sales Under =>
MBanner 35 35 35 35 35 35 35 35 34 35 35 35 36 1 11
BHunter 40 20 40 70 35 45 78 34 56 73 15 41 55 4 8
GJorgensen 60 62 47 68 40 53 62 88 18 15 72 12 19 7 5
TSmith 25 66 32 41 89 27 25 29 33 54 27 32 45 0 12

I get the first name and digits, then its just random numbers. But i can just mess around with yours until i get the output right. Thanks =].
How would i go about saving the string name of the person with the most quotaMissed?
applesnstuff wrote:
How would i go about saving the string name of the person with the most quotaMissed?
You could do that with an if statement

I added some detail
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	const int NUMSALES = 12;
	int sales[NUMSALES];
	int quotaMissed = 0;
	int quotaReached = 0;
	int totSalesperson;
	int quota;
	int i = 0;
	string salesPerson;
	string biggestLoser;
	int mostQuotaMissed = 0;
	string filename = "prog3a.txt";
	

	ifstream ifile;
	ifile.open(filename);

	if(ifile.fail())
	{
		cout << "File " << filename << " failed to open";
		cin.ignore(100, '\n');
		return 1;
	}

	ifile >> totSalesperson;
	cout << "Total number of salesPeople: " << totSalesperson << endl << endl;

	for (int count = 0; count < totSalesperson; count++)
	{
	
		//input salesPerson and quota
		ifile >> salesPerson >> quota;
		
		//input sales
		for(i = 0; i < NUMSALES; i++)
			ifile >> sales[i];

		// count the number of months the salesperson reached his quota
		for(i = 0; i < NUMSALES; i++)
		{
			if(sales[i] < quota)
				quotaMissed++;
			else
				quotaReached++;
		}

		//saves the name of the worst salesman
		if (quotaMissed > mostQuotaMissed)
		{
			mostQuotaMissed = quotaMissed;
			biggestLoser = salesPerson;
		}
		
		salesPerson.resize(12, ' ');

		//Displays salsperson information to the screen
		cout << salesPerson << " " << setw(2) << quota << " " ;
		for (i = 0; i < NUMSALES; i++)
		{
			cout << setw(2) << sales[i] << ',';
		}
		cout << " " << left << setw(2) << quotaMissed << " " << setw(2) << quotaReached << endl;

		//resets counters
		quotaMissed = 0;
		quotaReached = 0;

	}

	cout << "\nThe biggest Loser is " << biggestLoser << endl;

	cin.ignore(100, '\n');
	return 0;
}
Topic archived. No new replies allowed.