May 22, 2015 at 2:38am UTC
When I'm typing the correct password, it's telling me incorrect. Where did I go wrong? Please explain.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <iostream>
using namespace std;
int displayMenu() {
int choice;
cout << "Welcome to Chase financial security!" << endl;
cout << "Choose the option you want, below: \n" << endl;
cout << "1. Access your bank account? " << endl;
cout << "2. Access your deposit account?" << endl;
cout << "3. Access your transfer account?" << endl;
cin >> choice;
return choice;
}
bool accessedMenu() {
string password = "codex23jv" ;
string input;
cout << "Enter password to access this option." << endl;
cin >> input;
if (input == password) {
true ;
}
return false ;
}
int main() {
switch (displayMenu()) {
case 1:
case 2:
case 3:
if (accessedMenu()) {
cout << "Access granted." << endl;
} else {
cout << "Access denied, password incorrect." << endl;
}
break ;
default :
cout << "The option you have enter is invalid." << endl;
}
return 0;
}
Last edited on May 22, 2015 at 3:52am UTC
May 22, 2015 at 2:59am UTC
You are missing a return
before the true, otherwise that statement does nothing.
May 22, 2015 at 3:05am UTC
Wow I just realized that too lol, thank you!
May 22, 2015 at 10:46am UTC
As the return value of operator== is already true or false, you could just do this:
1 2 3 4 5 6 7
bool accessedMenu() {
string password = "codex23jv" ;
string input;
cout << "Enter password to access this option." << endl;
cin >> input;
return (input == password); // just return the result of the comparison
}
Andy
Last edited on May 22, 2015 at 10:46am UTC