functions with password creating code

I'm finding it really hard to understand how functions and bool types are implemented..
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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    bool green(string password); // function prototype
    string password;
    cout << "whats ur password? \n" ;
    getline (cin, password, '\n');
    bool green (password) // error here saying "'bool green' redeclared as different kind of symbol"
    {

            return password == "google";
    }
    if (green)
        {
            cout << "Go on through!" << '\n';
        }
    else
        {
            cout << "Wrong password" << endl;
        }
return 0;
}

I've re-written it in different ways and there's always one error or another when it comes to the function I'm trying to create.. which it's purpose is to check if the password is 'green'. Any enlightenment is hugely appreciated as I'm just going in circles right about now..
You have to specify the type of the parameters when defining a function. You also cannot define functions inside other functions so you have to put the definition of green outside of main.
1
2
3
4
bool green(string password)
{
	return password == "google";
}


To call the function on line 16 you have to put parentheses with the argument you want to send to the function inside after the function name.
if (green(password))
Last edited on
Thank you very very much
Topic archived. No new replies allowed.