Skip to content

Instantly share code, notes, and snippets.

@Battleroid
Created March 5, 2013 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Battleroid/5088013 to your computer and use it in GitHub Desktop.
Save Battleroid/5088013 to your computer and use it in GitHub Desktop.
Continually asks for password until the correct answer is entered.
#include <iostream>
#include <string>
using namespace std;
int main () {
string passcode = "123";
string guess;
bool correct = false;
do {
cout << "Enter password: ";
cin >> guess;
if (guess.compare(passcode) != 0) {
cout << "Incorrect. Try again." << endl;
} else {
cout << "Correct!" << endl;
correct = true;
}
} while (!correct);
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment