| #include <iostream> |
| #include <time.h> |
| #include <windows.h> |
| |
| using namespace std; |
| |
| bool finished; |
| |
| int GuessFunc(int guess, int randNum) |
| { |
| if (guess == randNum) |
| { |
| cout << "You got the correct number! Congrats d00d!\n"; |
| finished = true; |
| } |
| else if (guess > randNum) |
| { |
| cout << "The number you guessed is too big. Try a smaller one!\n"; |
| } |
| else if (guess < randNum) |
| { |
| cout << "The number you guessed is too small. Try a bigger one!\n"; |
| } |
| } |
| |
| |
| int main() |
| { |
| char ans; |
| do { |
| srand(time(NULL)); |
| int guesses = 0; |
| int guess; |
| int randNum = rand() % 10 + 1; |
| finished = false; |
| system("cls"); |
| |
| cout << "Welcome to my guessing game. You have only 3 guesses. So make a wise choice.\n"; |
| cout << "The number you have got to guess is between 0 and 10. Get guessing now ;). You WILL get clues.\n\n"; |
| while(guesses != 3 && finished == false) |
| { |
| cout << "Guess: "; |
| cin >> guess; |
| GuessFunc(guess, randNum); |
| guesses++; |
| } |
| if (finished == true) |
| { |
| cout << "You guessed it correct, play again? ( Y / N )\n"; |
| cout << "> "; |
| cin >> ans; |
| } |
| else |
| { |
| cout << "It looks like you have used up your 3 guesses. Play again? (Y / N )\n"; |
| cout << "> "; |
| cin >> ans; |
| } |
| } while ((ans == 'Y') || (ans == 'y')); |
| } |