ok. I finished up the code finally, but i'm still having the same problem. I don't see how these counters aren't working right. If someone can help me out i'd appreciate it. thanks.
Code:
/* Program Name: prog3
Author: Javier Guzmanv
Narrative: Determine number of months the salesperson did or didn't meet quota.
If more than 20% didnt meet quota, a campaign should be implemented.
Identify the worst salesperson and consider firing him/her.
Inputs: prog3a.dat - input file
Format: number of salespeople - int
salesperson name - string
quota - int
12 individual months - int
Output: Ref. Fig3
Operations:
1) Attach to file prog3a.dat
2) If unsuccessful - display error message
3) Get number of salespeople
4) For every salesperson
a) If quota is less thn any monthly sales, add one to the under
counter.
b) If quota is equal to or greater than monthly sales, add one to the
over counter.
c) Continue steps a & b until all 12 months are used.
d) If under is greater than zero add 1 to the yearly quota.
5) a) Divide yearly quotas by total salespeople to get yearly percentage.
b) If yearly percentage is greater than 20% display a "Sell it
or Else" campaign.
6) Display which sales person is the worst and consider firing him/her.
*/
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
//Difine variables
int totalPeople; //from inputfile
string salesName; //from input file
int quota; //from input file
int underCounter;
int overCounter;
int quotaPercent;
double quotaDecimal; //decimal before turning until percent
int yearlyUnder = 0; //if under is greater than zero add to this counter
int maxunderCounter = 0;
string maxsalesName;
//Individual months
int monthJan;
int monthFeb;
int monthMar;
int monthApr;
int monthMay;
int monthJun;
int monthJul;
int monthAug;
int monthSep;
int monthOct;
int monthNov;
int monthDec;
ifstream ifile("prog3b.dat"); //opens file3a.dat
if(ifile.fail()) //checks to see if file was able to open
{
cout << "Can't find file prog3b.dat" <<endl; //displays if file cannot be found
system("PAUSE");
return(0);
}
ifile >> totalPeople;
cout << "Total Salespeople: " << totalPeople << endl;
cout << endl << "Salesperson\tQuota\t\tMonthly Sales\t\t\tUnder\t=>" << endl;
ifile >> salesName >> quota >> monthJan >> monthFeb >> monthMar >> monthApr >> monthMay >> monthJun >> monthJul >> monthAug >> monthSep >> monthOct >> monthNov >> monthDec;
while(!ifile.eof())
{
underCounter = 0;
overCounter = 0;
if (quota < monthJan)
{
underCounter++;
}
else
{
overCounter++;
}
if (quota < monthFeb)
underCounter++;
else
overCounter++;
if (quota < monthMar)
underCounter++;
else
overCounter++;
if (quota < monthApr)
underCounter++;
else
overCounter++;
if (quota < monthMay)
underCounter++;
else
overCounter++;
if (quota < monthJun)
underCounter++;
else
overCounter++;
if (quota < monthJul)
underCounter++;
else
overCounter++;
if (quota < monthAug)
underCounter++;
else
overCounter++;
if (quota < monthSep)
underCounter++;
else
overCounter++;
if (quota < monthOct)
underCounter++;
else
overCounter++;
if (quota < monthNov)
underCounter++;
else
overCounter++;
if (quota < monthDec)
underCounter++;
else
overCounter++;
if (underCounter > 0)
{
yearlyUnder++;
}
//Displays output
cout << "\n" << salesName;
if(salesName.length() < 8)
{
cout << "\t\t";
}
else
{
cout << "\t";
}
cout << quota << "\t" << monthJan << " " << monthFeb << " ";
cout << monthMar << " " << monthApr << " " << monthMay << " " << monthJun << " ";
cout << monthJul << " " << monthAug << " " << monthSep << " " << monthOct << " ";
cout << monthNov << " " << monthDec << "\t" << underCounter << "\t" << overCounter;
ifile >> salesName >> quota >> monthJan >> monthFeb >> monthMar >> monthApr >> monthMay >> monthJun >> monthJul >> monthAug >> monthSep >> monthOct >> monthNov >> monthDec;
if (maxunderCounter < underCounter)
{
maxsalesName = salesName;
}
}
quotaDecimal = yearlyUnder / totalPeople;
if (quotaDecimal > .20)
{
quotaPercent = quotaDecimal * 100;
cout << "\n\nA Sell IT! OR Else Campaign must be mounted - " << quotaPercent;
cout << "% did not make yearly quotas" << endl;
cout << "\nConsider Firing: " << maxsalesName << endl;
}
cout << "\n\n";
system("PAUSE");
return(0);
}
output looks like this:
Code:
Total Salespeople: 6
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 7 5
GJorgensen 60 62 47 68 40 53 62 88 18 15 72 12 19 5 7
LLewis 35 56 37 40 49 37 28 39 43 54 37 42 45 11 1
JMathers 25 31 38 25 43 53 26 26 33 27 45 38 31 11 1
TSmith 25 66 32 41 89 27 25 29 33 54 27 32 45 11 1
A Sell IT! OR Else Campaign must be mounted - 100% did not make yearly quotas
Consider Firing: TSmith
Press any key to continue . . .