eternal loop

I keep getting this loop but my program compiles.
#include "RAHIM.H"
#define HEAD1 "GO-BROKE-AND-LAYOFF MANUFACTURING COMPANY"
#define HEAD2 "EMPLOYEE_NAME HOURS PAY_RATE GROSS_PAY PENSION_PLAN NET_PAY"
#define LINE "-----------------------------------------------------------------"
#define INFILE"P05.DAT"

int main()
{char employee_name[16];
double hours_worked,hourly_rate,gross_pay,pension_plan,net_pay,
total_hours_worked=0,total_gross_pay=0,total_net_pay=0;

clrscr();
cout <<" Amber D. Currie Assignment 5"<<endl<<setw(50)<< HEAD1 <<endl<<setw(68)<< HEAD2<<endl
<< setw(68) <<LINE <<endl <<fixed <<setprecision(2);

ifstream Infile(INFILE);
assert(!Infile.fail());

Infile.get(employee_name[17]);
Infile>>employee_name>>hours_worked>>hourly_rate;
while (!Infile.eof())
{ if (hours_worked > 40) gross_pay= ( 40 + (hours_worked - 40) *1.5)*hourly_rate;
else gross_pay=(hourly_rate *hours_worked);

gross_pay = floor(gross_pay*100+0.5)/100;

pension_plan =( 30 * hourly_rate);

net_pay= (gross_pay-pension_plan);

total_hours_worked += hours_worked;
total_gross_pay += gross_pay;
total_net_pay += net_pay;

cout<<employee_name<<hours_worked<<hourly_rate<<gross_pay<<pension_plan<<net_pay;

Infile.get(employee_name,17);
Infile>>employee_name>>hours_worked>>hourly_rate;
} //while
Infile.close();
cout <<setw(68) << LINE <<endl<<setw(21)<<"TOTALS:"
<<setw(21) << total_hours_worked <<setw(25)<<total_gross_pay<<setw<<(20)<<total_net_pay<<endl
<<setw(68) << LINE;
gotoxy(1,24);
return 0;
} //main()
/*------------------function:net_pay()-----------------------------------*/
double net_pay(double gross_pay,double pension_plan)
{ double net_pay;
net_pay= (gross_pay - pension_plan);

net_pay=floor(net_pay *100 +0.5)/100;
return net_pay;
} //net_pay()
/*---------------function:pension_plan()---------------------------------*/
double pension_plan(double hourly_rate )
{ double pension_plan;
pension_plan =( 30 * hourly_rate)*.061;

pension_plan=floor(pension_plan *100 +0.5)/100;
return pension_plan;
} //pension_plan()

I'm a bit concerned that you've declared:

char employee_name[16];

i.e. a statically declared array of 16 chars, and then used it like this:

Infile.get(employee_name[17]);

You're indexing out of the bounds of the array here (valid indexes are 0 to 15). I see other interesting things going on in your code, but perhaps that will give you a starting point.

Feel free to post your next attempt (using the <> code tags please!).
Topic archived. No new replies allowed.