If and ells

Hi

I have a problem.

The problem is that I can’t seem to get this "if" and "ells" statements right.
I have only been programming for a month or so.
Here is a snippet of the original code :

int DoYouWantRestart;
cout << "Do you whant to Restart, enter 0 for no or 1 for yes ";
cin >> DoYouWantRestart;

int ref;
ref = 0;

if (DoYouWantRestart = ref) {cout << "Windows will not Reboot" << endl;
}
else {batfile << " -r";
}


Explanation for the code, OK the user has to choose 0 for "no" and 1 for "yes"
But every time I select "0", it goes to the alternative section (ells)

Am I declaring something wrong and how do a programmer use the if and ells statement with strings?

Help me
Thanx
This DoYouWantRestart = ref (note =) is assignment. What you want is comparison: DoYouWantRestart == ref (note ==)
Last edited on
Thanx it works now with the (==)

If I may ask what is the deference between the = and == I have seen this some ware but I don’t know what the diffract between the two is?
we use "=" when we want to assign a value to a place, for example
a=b;
this mean we assign the value of b into a.

"==" is use for comparison between 2 values (variables), for example
a==b;
this will compare the value store in a with the value in b.

Remember that the statement "a=b;" will jz assign b into a but
statement "a==b;" will return "true" if a is equal to b, and return "false" if a is not equal to b.
Thanx for the info and you all are greate help.
Topic archived. No new replies allowed.