I have this project do tonight. I cannot figure out what is wrong with my program. My first prompt tells me to enter "ID" and when I do the while loops ends and my program ends? Can someone help me?
//Cosimo Vilardo assignment #2
//Program to compute information about employee's
#include <iostream>
using namespace std;
int main()
{
double pay, hours, rate, week_pay, over_time, bonus, net_pay;
int id, man_stat, number_of_employees=0;
I think you meant to use != instead of == in your while loop. The way you have it now, your loop will never run unless the employee ID is -1. Remember: a while loop runs as long as the condition remains true.
you're setting man_stat to 1, and that's why it's always outputing "manager." I would assume that you would want to check it to see if it's one not to set it equal to it.
Did you fix the = to == problem on both of your if statements? I tested it just now and it appears to be working. Could you show us your current code and input/output?
while(id!=-1){ //enter -1 to end program
number_of_employees++;
cout<<"Enter employee hours worked >> ";
cin>>hours;
cout<<"Enter employee rate of pay >> ";
cin>>rate;
cout<<"Enter 1 for manager or 0 for employee >> ";
cin>>man_stat;
myfile<<"employee "<<id<<" worked "<<hours<<" hours at $"
<<rate<<" per hour ";
if(man_stat==1) //prints out manager status
myfile<<" manager"<<endl;
else
myfile<<" not a manager"<<endl;
if(hours<=40) //Computes weekly pay and over time hours
week_pay=hours*rate; //for each employee
else{
over_time=hours-40;
week_pay=(40*rate)+over_time*1.5*rate;
}
if(man_stat==1) //Computes the bonus for each employee
bonus=week_pay*.10;
else
bonus=25;
net_pay=week_pay+bonus; //Computes netpay. Weekly pay x bonus
myfile<<"weekly pay $"<<week_pay<<" bonus $"<<bonus<<" net pay $"
<<net_pay<<endl<<endl;