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
49
50
51
52
53
54
55
56
57
58
59
60
#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'));
}