In the interest of full disclosure, this is a lab assignment that is due tomorrow. We are allowed to work with classmates in/out of class on it, so I am not cheating by asking for help. i am much older than most of my classmates, so we don't associate outside of class. (kinda creepy for a 40 year old dude hanging out with teenagers no matter what the reason if you ask me)
I have to modify a program that I have previously written to include a loop. When I first wrote the program I was aggravated that it terminated after each execution even though looping was not a requirement. I researched how to get it to loop (started a thread about it on here for help). I wasn't aware at the time that I would have to make the same program loop later. I finally managed, with some help from my tutor, to figure out how to get it to loop by prompting the user to answer if they wanted to continue. This assignment is a bit different than what I had accomplished.
We are required to have it loop until the years of service entered are <=0, or >=99. I am pretty sure that it requires a pre-test condition, but have tried both pre and post-test conditions while trying to get it to work. It will loop, but will not exit when any of the exit numbers are entered. if you can spot my mistake, please offer some help or a hint. It would be greatly appreciated. Thanks ahead of time for any help you may offer.
Code:
//Travis
//CPT-168-A01
//2nd Program
#include
<iostream>
using
namespace std;
int
main()
{
system(
"color f0");
cout<<
"\t\t\t***********************************"<<endl;
cout<<
"\t\t\t* Travis *"<<endl;
cout<<
"\t\t\t* Second Program *"<<endl;
cout<<
"\t\t\t* CPT-168-A01 *"<<endl;
cout<<
"\t\t\t***********************************"<<endl;
int yrswrkd = 0;
double hrswrkd = 0.0, hrlyrat = 0.0,notpay = 0.0, otpay = 0.0, bnspay = 0.0, pay1 = 0.0, totpay = 0.0;
do
{
cout<<
"Please Enter Years of Service(Less than 1 or Greater than 98 to Exit): ";
cin>>yrswrkd;
cout<<
"Please Enter Hours Worked: ";
cin>>hrswrkd;
cout<<
"Please Enter Hourly Pay Rate: ";
cin>>hrlyrat;
if (hrswrkd > 40)
notpay = hrlyrat * 40, otpay = (hrswrkd - 40) * 1.5 * hrlyrat, pay1 = otpay + notpay;
else
pay1 = hrswrkd * hrlyrat;
cout<<
"Your Gross Pay Is: $"<<pay1<<endl;
if (yrswrkd >= 1 && yrswrkd <= 5)
bnspay = pay1 * .05;
else
if (yrswrkd >= 6 && yrswrkd <= 9)
bnspay = pay1 * .10;
else
if (yrswrkd == 10)
bnspay = pay1 * .15;
else
if (yrswrkd > 10)
bnspay = pay1 * .20;
//endif
//endif
//endif
//endif
cout<<
"Your Employee Longevity Bonus is: $"<<bnspay<<endl;
totpay = pay1 + bnspay;
cout<<
"Your Total Pay Is: $"<<totpay<<endl<<endl;
cout<<
"Thank You For Your Service!"<<endl<<endl;
}
while (yrswrkd >= 1 || yrswrkd <= 98);
cout<<
"HAVE A NICE DAY!!!"<<endl<<endl;
system(
"pause");
return 0;
}