Created
April 25, 2018 00:42
-
-
Save egroj97/ffd980f43367ff310aa694f558f1c666 to your computer and use it in GitHub Desktop.
A program that makes you guess a letter out and helps you if you have a hard time on it!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <ctime> | |
#include <cstdlib> | |
using namespace std; | |
int main() | |
{ | |
srand(time(NULL)); | |
int randNum = rand() % 26; | |
string letters = "abcdefghijklmnopqrstuvwxyz"; | |
string randomLetter; | |
randomLetter.push_back(letters[randNum]); | |
string letterGuess = ""; | |
cout << "Enter one lowercase letter: "; | |
getline(cin, letterGuess); | |
bool flag = false; | |
while (flag == false){ | |
if (letters.find(letterGuess) == string::npos or | |
letterGuess.size() != 1) | |
{ | |
cerr << "ERROR: The letter is not lowercase or there is more than one letter\n"; | |
getline(cin, letterGuess); | |
} | |
else if (letterGuess != randomLetter) | |
{ | |
if (letters.find(letterGuess) < letters.find(randomLetter)) | |
cout << "The letter you're guessing for comes after\n"; | |
else | |
cout << "The letter you're guessing for comes before\n"; | |
getline(cin, letterGuess); | |
} | |
else | |
{ | |
cout << "You guessed right!\n"; | |
flag = true; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment