im reading in from a txt file that looks like this:
4 6.75 120 4444
1 1200.00 1111
3 10000.00 3333
2 12.50 50 2222
-1
and bassically im trying to just read in one number at a time however im getting an infinite loop . im using a switch statement that is suppose to stop not at the end of file but when it comes to a -1
anyways heres the code any hep would be much apreicated
Code:
#include <iostream>
#include "pay.h"
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{ //start declarations
pay p;
string empnum;
int week=0;
int hour=0;
int pie=0;
char paycode;
double hoursal;
double comtotal;
double pricepie;
string inloc;
string outloc;
ofstream output;
ifstream input;
// end declarations
output<<fixed<<showpoint<<setprecision(2); //sets everything to two decimal points
cout<<"Where is the input file"<<endl; // takes in the inputfile location
getline(cin,inloc);
input.open(inloc.c_str(), ios::out);
cout<<"Where would you like the output file to be saved"<<endl;// asks where to save the output file
getline(cin,outloc);
output.open(outloc.c_str(), ios::out);
output<<setw(10)<<"WEEKLY PAY REPORT FOR THE WIDGET COMPANY"<<endl; //the heading for the ouput file starts here
output<<endl;
output<<"EMPLOYEE"<<setw(5)<<"WEEKLY"<<setw(5)<<"HOURLY"<<setw(5)<<"HOURS"<<setw(5)<<
"GROSS"<<setw(5)<<"PRICE"<<setw(5)<<"NUMBER OF"<<endl;
output<<"NUMBER"<<setw(5)<<"PAY"<<setw(5)<<"SALARY"<<setw(5)<<"WORKED"<<setw(5)<<
"SALES"<<setw(5)<<"PER PIECE"<<setw(5)<<"PIECES"<<endl; //the heading for the output file ends here
do
{
input>>paycode; // takes in the paycode from the file
switch(paycode) //all the computations done here calculating total payroll and the payment for each employee
{
case '1':input>>week;input>>empnum;p.weeklyPay(week);
output<<empnum<<setw(5)<<week;break;
case '2':input>>hoursal;input>>hour;input>>empnum;p.hourlyPay(hour,hoursal);
output<<empnum<<setw(5)<<p.hourlyPay(hour,hoursal)<<setw(5)<<hoursal<<setw(5)<<hour;break;
case '3':input>>comtotal;input>>empnum;p.commissionPay(comtotal);
output<<empnum<<setw(5)<<p.commissionPay(comtotal)<<setw(10)<<comtotal;break;
case '4':input>>pricepie;input>>pie;input>>empnum;p.piecePay(pricepie,pie);
output<<empnum<<setw(5)<<p.piecePay(pricepie,pie)<<setw(20)<<pricepie<<setw(5)<<pie;break;
case '-1':input.close();break; // close the input file when its -1
}
// p.getPayRollAmount(); //running total of the payroll updates every round the loop runs
}while(paycode !='-1'); //condition for the loop to keep running
output<<endl; //the rest of the output file starts here
//output<<"Total payroll: $"<<p.getPayRollAmount()<<endl;
output<<"Total number of managers paid: "<<p.getWeekly()<<endl;
output<<"Total number of hourly workers paid: "<<p.getHourly()<<endl;
output<<"Total number of commission works paid: "<<p.getCommission()<<endl;
output<<"Total number of piece workers paid: "<<p.getPiece()<<endl;
output<<endl;
output<<"Programmer: Johnny Gaffey"; // the last of the outputfile ends here
output.close(); //close the output file
cout<<endl<<"Processing complete";
return 0;
}//main
this is what the output is suppose to look like:
WEEKY PAY REPORT FOR THE WIDGET COMPANY
EMPLOYEE WEEKLY HOURLY HOURS GROSS PRICE # OF
NUMBER PAY SALARY WORKED SALES PER PIECE PIECES
4444 810.00 6.75 120
1111 1200.00
3333 820.00 10000.00
2222 687.50 12.50 50
total payroll: $3517.50
total number of managers paid: 1
total number of hourly workers paid: 1
total number of commission workers paid: 1
total number of piece workers paid: 1