I’m using the following code (it’s been super simplified to get to the root of my problem).
#include <iostream>
namespace std;
int user;
int submit(int);
int main() {
user = 1;
submit(user);
user = 2;
submit(user);
return(0);
}
int submit(int user) {
if (user = 1) {
printf("1");
} else if (user = 2) {
printf("2");
}
return(0);
}
I thought that this would print out “12” but instead I’m getting “11”. Isn’t the variable “user” getting redefined before the function is called for the second time?
What’s going wrong here?
Use
==, not=to check the values ofuser. You’re overwriting the values (with=) instead of comparing them (with==).