Dec 18, 2015 at 10:40am UTC
This is my code. I'm finding the total salary. The problem is, it doesn't give the correct output. I'm wondering if I missed out something
thank you :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
using namespace std;
int main()
{
int bonus, salary, year;
float sale, abonus, paycheck;
cout<<"Salary-$3000" <<endl<<endl;
cout<<"Number of years:" ;
cin>>year;
cout<<"Sales for the month:" ;
cin>>sale;
salary = 3000;
if (year<=5)
bonus = 10 * year;
else
bonus = 20 * year;
//additional bonus
if (sale < 5000)
abonus = 0;
else if (10000 >= sale >= 5000)
abonus = sale * 0.03;
else if (sale > 10000)
abonus = sale *0.06;
paycheck = salary + bonus + abonus;
cout<<endl<<endl<<endl;
cout<<"Paycheck:" <<paycheck<<endl;
system("pause" );
return 0;
}
Edit:
Output
Salary - $3000
Number of years:
Sales for the month:
Paycheck:
-----
Output (what it should be)
Salary - $3000
Number of years: //4
Sales for the month: //$6000
Paycheck: //Answer should be $5440
----
Output (Now)
Salary - $3000
Number of years: //4
Sales for the month: //$6000
Paycheck: //-1.07371e+008
Last edited on Dec 18, 2015 at 11:12am UTC
Dec 18, 2015 at 10:45am UTC
What input do you give it.
What output do you see.
What output did you expect.
if (10000 >= sale >= 5000)
This is definitely wrong.
Last edited on Dec 18, 2015 at 10:46am UTC
Dec 18, 2015 at 10:53am UTC
@Moschops
edited sorry...
I changed it to (sale <= 10000, sale >=5000)
The answer changed but it's still the wrong value
Last edited on Dec 18, 2015 at 11:03am UTC
Dec 18, 2015 at 12:07pm UTC
@mancer:
Do you understand what the comma operator in C++ actually does?