New Programmer

Hey guys im new to all this and im writing a script to output what my age is and if i enter it correctly it will spit out a text line saying Great job yada yada yada... Now, on the other hand if i input it incorrectly it should spit out that it is put in incorrectly and that i need to keep trying. (Almost like a password system). But it repeatedly is telling me that im entering it correctly and it closes the program ( i am using "Code:Blocks" ). Well here is my script. Tell me if you see what im doing incorrectly and if you can quickly explain that would be greatly appreciated. Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
    int a;

    cout << "What is mitchell's Age?";

    cin >> a;

    if ( a=16 ){
    cout << "That is correct";
    }
    else{
    cout << "That is wrong, Try again!";

    }

    return 0;
}
You need to use the comparison operator "==".
'=' is the assignment operator, so you're setting a to 16, and then checking if a == true, which in C++ is anything but 0.
So you think i should put it here?

if ( a==16 ){
cout << "That is correct";
}
else{
cout << "That is wrong, Try again!";
Yup.
It worked like a charm. Much appreciated. Excuse me for not understanding as-well. Just started learning this stuff. Thank you once again.
Topic archived. No new replies allowed.