True and False problem

Hi there, I'm new to the programming area so I've just been testing a few things out with a 'how old are you' script, and I'm struggleing on true and false statements,

A lot of what I've done is guese work so not surprising it's wrong, but heres the bit of the script I'm strugleing with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int school;
bool schoola = false;
school = age <=16;
       cout << "second part.." <<endl;
       cout << "so you are " << age << " years old" <<endl;
       if (school)
       {
                  cout << "you are still in school" <<endl;
       
       }
    if (schoola = true)
       {
                 cout << "yes it is true then you are still in school" <<endl;       
       }
    if (schoola = false)
       {
                cout << "you arent in school but its saying its true neway!" <<endl;
       }


The code allways comes out with the true statement, no matter what age I put in.

this is only part of the full script but the rest of it I havnt had a problem with. Any tips on how to do the true/false correctly would be much appreciated.

Thnx for reading
Rob
if (schoola = true)

= is assignment
== is comparison

you want == here

Same problem with line 15
Line 2 assigns false to the variable schoola.
Line 11 assigns true to the variable schoola.
Line 15 assigns false to the variable schoola.

I believe you want to compare the value of schoola in lines 11 and 15. To compare, use the == operator, not =.

Hope this helps.
ok yup <_< should of looked around harder. Thnx for that.
Topic archived. No new replies allowed.