RUSES
Would you like to react to this message? Create an account in a few clicks or log in to continue.
April 2024
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
2930     

Calendar Calendar


Passwords help

2 posters

Go down

Passwords help Empty Passwords help

Post  ElliottH Sun Mar 18, 2012 3:45 am

I'm trying to include a password into my game, but it isn't working properly. I'm getting a bit confused about using strings :/

Code:

cout << "Input a password:" << endl;
   string p;
   cin >> p;

   if (p == "banana")
      return 1;
   else if (p == "define")
      return 2;
   else if (p == "pirate")
      return 3;
   else
      {cout << " Invalid password" << endl;
      return 0;}
ElliottH
ElliottH
Admin

Posts : 16
Join date : 2012-02-23

Back to top Go down

Passwords help Empty Re: Passwords help

Post  ElliottH Sun Mar 18, 2012 4:11 am

ahhh ignore this! i found the problem elsewhere..
ElliottH
ElliottH
Admin

Posts : 16
Join date : 2012-02-23

Back to top Go down

Passwords help Empty Re: Passwords help

Post  Alex Sun Mar 18, 2012 5:11 am

Just for future reference, comparing strings

Code:
string cat = "cat";
if (cat.compare("dog") == 0) cout << "the strings are equal";
else cout << "the strings aren't equal";
Alex
Alex

Posts : 67
Join date : 2012-02-23
Location : Come at me bro

Back to top Go down

Passwords help Empty Re: Passwords help

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum