terminating a loop

I would like to have the program run otherwise terminate when employee number or 'empnum' is entered as 0. I did some research and couldn't find an answer that would help me.I'd appreciate any input, thank you. { // variables
int empnum ;
double grosspay, statetax, fedtax, FICA, tottax, netpay;


do
{ cout << "\nPlease enter your employee number or 0 to terminate this program.\n";
cin >> empnum;


cout << "\nEnter employee gross pay\n";
cin >> grosspay;
cout << "\nEnter state tax amount\n";
cin >> statetax;
cout << "\nEnter federal tax amount\n";
cin >> fedtax;
cout << "\nEnter FICA amount\n";
cin >> FICA;

tottax = statetax + fedtax + FICA;
netpay = grosspay - tottax;

if ( empnum != 0 )
{
if (grosspay < tottax )
cout << "\nGross pay can't be less than the total tax amount\n";

else if (grosspay < 0 || statetax < 0 || fedtax < 0 || FICA < 0)
cout << "\nNegative entries are not valid\n";

else
{ cout << "_____________________________________________________" << endl;
cout << fixed << showpoint << setprecision(2)<< endl;
cout <<"Employee number: "<< empnum << endl;
cout <<"Gross pay: $"<< grosspay << endl;
cout <<"State tax: $"<< statetax << endl;
cout <<"Federal tax: $"<< fedtax << endl;
cout <<"FICA: $"<< FICA << endl;
cout <<"Net pay $"<< netpay << endl;
}
}
}while ( empnum != 0 );
To terminate program use exit(exitcode)
example:
1
2
3
4
5
6
7
while(1){
int x;
cin>>x;
if(x==1){
exit(0); //terminates the program
 }
}
Use break; to jump out of the current loop you are in.
Hey thanks guys for the input. I went with Hazer's plan and the project executed just as I wanted it to.
Topic archived. No new replies allowed.