logical error?

Hey guys, i'm a college freshman taking an introductory C++ course.
I'm fairly familiar with flow control, however whenever I try to run the program below it seems that my "if" statements inside my do while loop don't appear to get checked. I'm not sure what is wrong with my code.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
using namespace std;

int main()
{
int level, performance, experience, salary, bonus;
char proceed;

do
{

cout << "is the employee a manager or non-manager? (1 for manager, 0 for non-manager) \n";
cin >> level;
cout << "what is their current salary? \n";
cin >> salary;
cout << "how have they performed? (0 for Poor, 2 for OK, 3 for Good) \n";
cin >> performance;
cout << "how many years of experience do they have? \n";
cin >> experience;


	// for non-managers
	if(level = 0)
	{

         // *Im having trouble with these if statements*


		if((experience <= 15) && (experience > 5))
		{
			if(performance != 3)
			{
				bonus = salary*1.15;
				cout << "new salary is: " << bonus;
			}
		}
		else if(experience > 15)
		{
			if(performance == 3)
			{
				bonus = salary*1.15;
				cout << "new salary is: " << bonus;
			}
		}
		else if(experience <= 5)
		{
			if(performance = 3)
			{
			bonus = salary*1.10;
			cout << "new salary is: " << bonus;
			}
		}
		else
			cout << "not elegible for a bonus";
	}

	// for managers
	else if(level = 1)
	{

        // *and also these*

		if(experience <= 15)
		{
			if(performance !=0)
			{
				bonus = salary*1.15;
			}
		}

	}

	cout << "would you like to continue? (N for no, anything else for yes)\n";
	cin >> proceed;
}
while(proceed != 'N');



return 0;
}


Any ideas?

Edit: any advice is greatly appreciated!
Last edited on
= is not a relational operator, it's the assignment operator. x = y the value of y into x and evaluates to the new value of x. In other words, the true branch of
 
if (x = 0){
will never execute, because it's equivalent to
1
2
x = 0;
if (0){

== is the equality operator.
I can't believe I failed to remember this, Thank you!!!
now I can get back to finishing it!

Cheers!
> I can't believe I failed to remember this

The compiler will remind you if you let it (compile with warnings enabled).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    int level = 8 ;

    if( level = 0 )     // LLVM -Wall -Wextra  warning: using the result of an assignment as a condition without parentheses
                        // LLVM -Wall -Wextra  note: place parentheses around the assignment to silence this warning
                        // LLVM -Wall -Wextra  note: use '==' to turn this assignment into an equality comparison
                        
                        // GNU -Wall -Wextra  warning: suggest parentheses around assignment used as truth value

                        // microsoft -W4 -analyze  warning: Incorrect operator:  assignment of constant in Boolean context. Consider using '==' instead.
                        // microsoft -W4 -analyze  warning: assignment within conditional expression
    {
        // ...
    }
}

http://coliru.stacked-crooked.com/a/96c416843d5a78ac
http://rextester.com/SJVKW62894
I'm using g++ to compile my programs using a program called "PuTTY", not an IDE.

for some reason, it lets me compile just fine with no errors.
either way, ill be sure to remember it next time.
Last edited on
Without an IDE, it is easier; use these options on the command line:
g++ -std=c++14 -Wall -Wextra -pedantic-errors

With an old version of the compiler, use std=c++11 instead of std=c++14
Ill give it a try next time, thanks!
Topic archived. No new replies allowed.