What I'm wanting to know is how do I make this whole if else repeat until an invalid number is entered. I believe line 20 (the condition) does not function to do anything at the moment how should I change that?
#include<iostream>
usingnamespace std;
int main()
{
constdouble PAY=16.78;
constdouble FED=.14;
constdouble SOC=.06;
constdouble STATE=.05;
constdouble UNION=10;
constint INSUR=35;
int hours, dependents, base_hours=40;
double net,gross,h_overtime,p_overtime,soc_tax,fed_tax,state_tax,tot_ded;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
while (hours>0)
{
cout<<"How many hours did you work this week? (Enter 0 when finished)\n";
cin>>hours;
cout<< "How many dependents do you have?(Enter 0 when finished)\n";
cin>>dependents;
if (hours>40)
{ if (dependents>=3)
{ h_overtime=hours-40;
p_overtime=(PAY*1.5)*h_overtime;
gross=(base_hours*PAY)+p_overtime;
cout<<"Your gross pay is $"<<gross<<".\n";
fed_tax=gross*FED;
cout<<"Your federal tax deduction is $"<<fed_tax<<".\n";
soc_tax=gross*SOC;
cout<<"Your Social Security deduction is $"<<soc_tax<<".\n";
state_tax=gross*STATE;
cout<<"Your state tax deduction is $"<<state_tax<<".\n";
cout<<"You also have a $10 deduction for union dues and a $35 deduction toward insurance because of your three dependents.\n";
tot_ded=fed_tax+soc_tax+state_tax+UNION+INSUR;
net=gross-tot_ded;
cout<<"Your net take-home pay is $"<<net<<" this week.\n";
}
else
{ h_overtime=hours-40;
p_overtime=(PAY*1.5)*h_overtime;
gross=(base_hours*PAY)+p_overtime;
cout<<"Your gross pay is $"<<gross<<".\n";
fed_tax=gross*FED;
cout<<"Your federal tax deduction is $"<<fed_tax<<".\n";
soc_tax=gross*SOC;
cout<<"Your Social Security deduction is $"<<soc_tax<<".\n";
state_tax=gross*STATE;
cout<<"Your state tax deduction is $"<<state_tax<<".\n";
cout<<"You also have a $10 deduction for union dues.\n";
tot_ded=fed_tax+soc_tax+state_tax+UNION;
net=gross-tot_ded;
cout<<"Your net take-home pay is $"<<net<<" this week.\n";
}
}
else
{ if (dependents>=3)
{ gross=(hours*PAY);
cout<<"Your gross pay is $"<<gross<<".\n";
fed_tax=gross*FED;
cout<<"Your federal tax deduction is $"<<fed_tax<<".\n";
soc_tax=gross*SOC;
cout<<"Your Social Security deduction is $"<<soc_tax<<".\n";
state_tax=gross*STATE;
cout<<"Your state tax deduction is $"<<state_tax<<".\n";
cout<<"You also have a $10 deduction for union dues and a $35 deduction toward insurance because of your three dependents.\n";
tot_ded=fed_tax+soc_tax+state_tax+UNION+INSUR;
net=gross-tot_ded;
cout<<"Your net take-home pay is $"<<net<<" this week.\n";
}
else
{ gross=(hours*PAY);
cout<<"Your gross pay is $"<<gross<<".\n";
fed_tax=gross*FED;
cout<<"Your federal tax deduction is $"<<fed_tax<<".\n";
soc_tax=gross*SOC;
cout<<"Your Social Security deduction is $"<<soc_tax<<".\n";
state_tax=gross*STATE;
cout<<"Your state tax deduction is $"<<state_tax<<".\n";
cout<<"You also have a $10 deduction for union dues.\n";
tot_ded=fed_tax+soc_tax+state_tax+UNION;
net=gross-tot_ded;
cout<<"Your net take-home pay is $"<<net<<" this week.\n";
}
}
}
return 0;
}
When you declare house, it isn't initialized to a value, so it could be anything. Set it to some initial value so that the loop condition would be true from the start.