Guessing Game

Below is the code I've been working on the past few days. It is about the guessing game where the guesser will have to guess a secret number of the player whilst the player's role is to respond if his secret number is higher or lower, otherwise the guess is correct. If the number is higher or lower, the guesser will have to guess again, but only within 10 attempts and if he still cannot find the secret number within those 10 attempts, he will simply give up, otherwise, if he detect it within those attempts, he wins. However, the guesser will accuse the player of cheating when he was certain he has chosen the secret number but the player still denies it. My problem here is that I dont know how to add to this program the cheat part, and also when I run this program, it will not exit when the guesser detects the secret number within the 10 attempts, only it will does when he detects it in his first attempt, otherwise he will guess over and over again within another 10 attempts even if he detects it within those attempts. Well, can some1 show me how to write the whole exact program for this please? i dont know how to write them all in one program, the win part, the give-up part and the cheat part because i havent familiar yet with such kind of program. Any help will be highly appreciated. Thanks!

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
const int NUM = 4, MAX = 15, MIN = 1;
int guess;
int count = 0;
char response;

cout << "\t\tNumber Guessing Game" << endl << endl;
cout << "\tGuess a number between " << MIN << " and " << MAX << ": ";
cin >> guess;

if (guess == NUM)
{
cout << "Bob: You win\n";
}

else
{
count++;

while (guess != NUM)
{
while (count != 10)
{
if (guess > NUM)
{
cout << "\n\n\tAlice's guess is " << guess << "\n\tMy secret number is LOWER." << endl;
}
else if (guess < NUM)
{
cout << "\n\n\tAlice's guess is " << guess << "\n\tMy secret number is HIGHER." << endl;
}
else // guess number is correct
{
cout << "\n\n\tBob says: You win." << endl;
}

count++;

if (count == 10 && guess != NUM)
{
cout << "\n\n\tAlice says: I give up" << endl << endl;
}

cout << "\n\n\tGuess a number between " << MIN << " and " << MAX << " again: ";
cin >> guess;
}
}
}

system ("PAUSE");
return 0;
}
Last edited on
Topic archived. No new replies allowed.