Hi, I have a problem here with the c++ if statement.

if (adult=1)
hotel=(adult*hotel)+(children*0.5*hotel) +(baby*0);
else if (adult=2)
hotel=(adult*260*0.85) +(children*0.5*260) +(baby*0);
else if (adult>2)
hotel=(adult*hotel*0.8) +(children*0.5*hotel) +(baby*0);

the above is a small part of the code i'm doing. Problem here is, It is changing my adult input to 1 no matter what digits i enter.
input for adult is 4
however, the statement (adult>2) is not carried out whereas it is carried out under (adult=1).
i displayed the 'adult' before and after the if statements. before, it is fine but after, it isn't.
Need help here, thanks :)

Edited 3 Years Ago by happygeek: fixed formatting

1.) Please use [code-syntax]...code tags... [/code]. They make your code easier to read.

2.) You are making a common rookie mistake. You're using assignment statements instead of equality statements. Take another look at the operators used in your comparisons.

Edited 6 Years Ago by Fbody: n/a

You need to use == when doing if statements. You are suppose to compare(==) not assign(=) in if statements.

A few seconds too late i suppose ;)

Edited 6 Years Ago by Grn Xtrm: n/a

This question has already been answered. Start a new discussion instead.