creating a password for some text

Hi, I am new to C++, this is my first post, bla bla bla...(you've probably seen this for hundreds of times :D)
I am experimentng with some program.
I want to create a program that will output something only if number "99" is typed. This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

bool check(int);

int main() {
    int password;
    bool final;
    cout << "Enter password: ";
    cin >> password;
    final = check(password);
    if (final = true)
          {
              cout << "my secret is: DAMN I AM HUNGRYYYY!" <<endl;
          }
    else
          {
              cout << "incorrect password :D" <<endl;
          }

}



bool check (int password) {
    if (password = 99)
         {
             return true;
         }
    else
         {
             return false;
         }
}

problem is, whatever number I type I always get my secret revealed :D .
help
Last edited on
the problem is on line 26:
= sets a variable
== compares two variables and returns true if they are equal.

Just so that you know, your check function may as well look like this:
1
2
3
bool check(int password){
    return password == 99;
}


edit: note that you're doing the same mistake on line 12.
Good luck
Last edited on
hahahah! what problem are you having?
Topic archived. No new replies allowed.