The problem is:
The state government has decided to give a 4% raise and $500 one-time bonus to non-teacher state employees. Teachers will get a 7% raise and $200 one-time bonus. Write a program that asks a state employee’s salary and whether he is a teacher or not. Calculate and display the employee’s new salary and bonus. [Hint: The program can ask the employee to enter ‘Y’ or ‘N’ to indicate whether he is a teacher or not. Some users may enter a lowercase letter while some others may enter an uppercase letter. You program must be also to handle both.]
I think I have everything right, except when I enter the non-teacher salary, the output is wrong. For example, when I enter 30000 the output should be 31200 but instead I'm getting 32100. Can anyone help?
using namespace std;
double oSalary = 0.0;
char Teacher ;
cout << "Enter your salary: $" ;
cin >> oSalary ;
cout << "Are you a teacher? (Put Y for yes and N for no.): " ;
cin >> Teacher ;
If you had everything right, you wouldn't be getting the wrong answer.
There are two things wrong with your if statement.
1) You're using the assignment operator = instead of the equality operator ==.
2) You can't specify multiple right side conditions. You have to test each condition. The compiler is going to evaluate ('Y' || 'y') first, then assign the result to Teacher. Not what you want.
Your if statement should be as follows:
if (Teacher == 'Y' || Teacher == 'y')
PLEASE USE CODE TAGS (the <> formatting button) when posting code.