Code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Start ();
void GetResults ();
int input, correctAnswer, lifesLeft, maxGuesses;
char caseTest;
void
Start ()
{
input = 0;
correctAnswer = 0;
lifesLeft = 0;
maxGuesses = 6;
cout << "\n------------------------------------------------------------------------------\n";
cout << "Select difficulty mode, You are restricted to five\nlifes on any difficulty.\n"; // the user has to select a difficutly level
cout << "1 = 10 numbers to choose from (easy) \n";
cout << "2 = 15 numbers to choose from (intermediate) \n";
cout << "3 = 25 numbers to choose from (master) \n";
cout << "Anything other than 1, 2 or three will end the program!\n";
cout << "\n------------------------------------------------------------------------------\n";
caseTest = 15;
cin >> caseTest; // read the user's choice
cout << "\n";
switch (caseTest)
{
case '1' : maxGuesses = 10; // the random number will be between 0 and max
cout << "Easy?, you're soft! ):\n\n";
break;
case '2' : maxGuesses = 15;
cout << "Ohh... starting to get brave are we?\n\n";
break;
case '3' : maxGuesses = 25;
cout << "So you have a master brain huh?, we'll see...\n\n";
break;
default : exit(0);
break;
}
lifesLeft = 5; // number of lifes
srand( (unsigned)time( NULL ) ); // init Rand() function
correctAnswer = rand() % maxGuesses; // random value between 0 and maxguesses
GetResults();
}
void
GetResults ()
{
if (lifesLeft <= 0)
// if player has no more life then he lose ZOMG^^
{
cout << "You lose punk!, muhahahahaha.\n\n";
Start();
}
cout << "Type a number to see if you're correct: \n";
cin >> input; // read user's number
if ((input>maxGuesses) || (input<0)) // if the user number isn't correct, restart
{
cout << "\nError>> Enter a number that's\nwithin the specified range!\n";
GetResults();
}
if (input == correctAnswer)
{
cout << "You've Done it! congrats.\n\n"; // the user found the secret number
Start();
}
else if (input > correctAnswer)
{
cout << "Your answer was higher than the correct one\n";
lifesLeft = lifesLeft - 1; // -1 to the user's life
cout << "Number of remaining life(s) are:\n" << lifesLeft << "\n\n";
GetResults();
}
else if (input < correctAnswer)
{
cout << "Your guess was smaller than the correct one\n";
lifesLeft = lifesLeft - 1;
cout << "Number of remaining life(s) are:\n" << lifesLeft << "\n\n";
GetResults();
}
}
int
main ()
{
cout << " ";
cout << " ";
cout << "\n########################### GuessWhat? #########################\n";
cout << "\nWelcome to this lame guessing gamer\n";
cout << "You have to guess the number i'm thinking of (would you believe)\n";
cout << "You have a maximum of 5 guesses, so choose carefully!\n";
cout << "######################################################################\n";
Start();
return 0;
}



