+ 2

C++ if

help me plz. input: hours, hourlyrate; if hours >45 bonus is 500, >40 & <=45 bonus is 250, >35 & <=40 bonus is 150.. display the basic salary, bonus and total salary.. hours*hourlyrate to get basic salary and basic salary + bonus to get total salary. my problem is how to get the output of bonus and how to add it with the basic salary. any help will be appreciated.

4th Jul 2017, 12:53 PM
kenn lingcay
kenn lingcay - avatar
5 Answers
+ 7
nice. replace cout << (bonus value) lines with bonus = (what ever the bonus value is) i.e cout << 500 .. should say bonus = 500; edit: if you want to show what bonus the user got write cout << "Bonus: " << bonus << endl; after the if statements somewhere of your choosing
4th Jul 2017, 1:11 PM
jay
jay - avatar
+ 5
have you any code for this problem that you have tried?
4th Jul 2017, 12:58 PM
jay
jay - avatar
+ 3
thought so :)
4th Jul 2017, 10:54 PM
jay
jay - avatar
+ 2
yes this is what I'd tried... #include<iostream> using namespace std; int main() { double hours,hourlyrate,salary,total,bonus=0; cout<<"enter hours: "; cin>>hours; cout<<"\nhourly rate: "; cin>>hourlyrate; if (hours>45) { cout<<500; } else if (hours>40 && hours<=45) { cout<<250; } else if (hours>35 && hours<=40) { cout<<150; } else { cout<<"invalid"; } salary=hours*hourlyrate; total=salary+bonus; cout<<"\n\nsalary: "<<salary; cout<<"\ntotal: "<<total; return 0; }}
4th Jul 2017, 1:07 PM
kenn lingcay
kenn lingcay - avatar
+ 2
thank you so much for the help sir, its my assignment for tomorrow. :)
4th Jul 2017, 1:34 PM
kenn lingcay
kenn lingcay - avatar