Make a loop for a different number of years and stop in years worth enter as 0, 99 or higher or negative numbers Prompt the user for the salary per year and calculate the Christmas bonus based on the number of years work as follow for 1 to 5 years 1% of gross pay, and six or more years to percent of gross pay
#include <iostream>
using namespace std;
int main()
{ int gpay, years, bonus;
while (1)
{
cout<<"Enter your gross pay :";
cin>>gpay;
cout<<"Enter number of years of work :";
cin>>years;
if ( years > 0 && years < 5)
{
bonus = gpay*0.1;
cout<<"Your Christmas Bonus is : "<<bonus;
break;
}
else if (years > 5 && years < 99)
{
bonus = gpay*0.2;
cout<<"Your Christmas Bonus is : "<<bonus;
break;
}
else if (years < 0 || years > 99)
{
cout<<"Please enter years between 0 or 99"<< endl;
continue;
}
}
return 0;
}
Comments
Leave a comment