need help, can't see what's wrong

here's my program, hope somebody will see where I went wrong.
#include <iostream>

using namespace std;

int main()
{
int response;
int bonus = 0;
int salary = 0;
int newsalary = 0;

cout << " What is your salary: ";
cin >> salary ;
cout << "Are you a teacher y/n: ";
cin >> response ;

if (response = 'y'||'Y')
{

newsalary = salary * 1.07;
cout << "New salary in dollars :"<< newsalary << endl;
cout << "Bonus = 200 dollars" << endl;
}

else if (response = 'n'||'N')
{
newsalary = salary *1.04;
cout << "New salary in dollars :"<< newsalary << endl;
cout << "Bonus = 500 dollars" << endl;

}


//system("pause");
return 0;
}
newsalary should probably be a double; since salary*1.04 is.

response should be a char; 'y' or 'n'

> if (response = 'y'||'Y')

= is assignment; equality comparison is ==

'y'||'Y' This doesn't work the way you expect it to work. Hint: anything || 'Y' will always evaluate to true.

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
#include <iostream>

int main()
{
    using namespace std;

    int salary = 0;

    cout << " What is your salary: ";
    cin >> salary ;

    /*int*/ char response; // ***
    cout << "Are you a teacher y/n: ";
    cin >> response ;

    /*int*/ double newsalary = 0; // ***
    double bonus = 200 ; // ***

    //if (response = 'y'||'Y')
    if( ( response == 'y' ) || ( response == 'Y' ) ) // ***
    {
        newsalary = salary * 1.07;
    }

    //else if (response = 'n'||'N')
    else if( ( response == 'n' ) || ( response == 'N' ) ) // ***
    {
        newsalary = salary *1.04;
        bonus = 500 ;
    }

    // else { the input was not 'y' or 'n' } // ***

    cout << "New salary in dollars : "<< newsalary << '\n'
         << "Bonus = " << bonus << " dollars\n" ;
}
Thank you very much for your help. I really appreciate it.
Topic archived. No new replies allowed.