There are two questions. I did the first question but i didn't understand the second question. Here is the questions.
Write a program that has user enter a salary. If salary 20000 or less, give 30% raise, if more than 20000 and less than 40000 give 20 % raise. If 40000 or more but less than 60000 give 10 % raise.
This is Second question.
Raise using OR AND
Write a program that gives a raise on same criteria as first RAISE assignment, but this time use AND like this if( salary <= 60000 && salary >40000)
Also use OR to first check that use didn't enter negative number or too large.
if(salary <0 || salary >1000000)
This is what i got.
#include<iostream>
using namepspace std;
int main()
{
double sal = 0;
cout<<"enter number"<<endl;
cin>>sal;
If (sal<=20000)
sal = sal + 0.30*sal;
if (sal>20000 && sal>40000)
sal = sal + 0.20*sal;
if (sal>=40000 || sal>60000)
sal = sal + 0.10*sal;
cout<<sal;
return 0;
}
When posting code, please use code tags. Highlight the code and press the <> button to the right of the edit window.
I don't understand the second question either. That's a common way to write the code and indeed it's the way you seem to have written it. So I'd say you've already answered the second question :).
Double check your "if" statements. Right now a salary of 30000 won't get a raise.
A good way to code this sort of thing is to start at the bottom of the range and work your way up. At each step you only need to make one comparison. For example, at line 14 I don't have to check if it's greater than 20,000 because if it wasn't then one of the previous if's would have caught it.
Coding it this way also ensures that you won't miss a number.