+ 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.
5 Respostas
+ 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
+ 5
have you any code for this problem that you have tried?
+ 3
thought so :)
+ 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;
}}
+ 2
thank you so much for the help sir, its my assignment for tomorrow. :)