Alright, so I am a beginner "coder" and I was messing around with a game called "HiLo" and I finally got it to display different results depending on how many guesses you attempt. However, I'm not sure how to implement my next step. What I want to do is tell the user a certain message and end the game if they reach too many guesses. Something like "You've used 20 guesses already. Forget it. Game Over." What line should I use or how should I put it in?
Also, I have heard bad things about the system pause but I was taught that way. I replace with "cin.get()" or something like that, right?
Code
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(0));
int guessNum = rand() % 100;
int guess;
int attempts = 0;
cout << "This is the \"Hi Lo Game\"\n" << endl;
cout << "Guess a number for 1 - 99: " << endl;
while (guess != guessNum)
{
cin >> guess;
if (guess > guessNum)
{
cout << "Sorry, that guess is too high. Guess again.\n" << endl;
}
if (guess < guessNum)
{
cout << "Sorry, that guess is too low. Guess again. \n" << endl;
}
attempts++;
}
if (guess == guessNum)
{
cout << "Game Over. That was the right guess. The correct number was " << guessNum << "." << endl;
}
if (attempts == 1)
{
cout << "Incredible!! You guessed the correct number in a single guess!\n" << endl;
}
if (attempts > 1 && attempts <= 5)
{
cout << "Well done. You only needed " << attempts << " guesses to get the right answer.\n" << endl;
}
if (attempts > 5 && attempts <= 10)
{
cout << "Meh. You could have done better. You needed " << attempts << " guesses to win.\n" << endl;
}
if (attempts > 10)
{
cout << "Terrible. Keep playing to improve. It took " << attempts << " attempts to get the answer.\n" << endl;
}
system("pause");
return 0;
}Also, I have heard bad things about the system pause but I was taught that way. I replace with "cin.get()" or something like that, right?
Humorous stupidity. Post #27 and further...
Quote:https://hackforums.net/showthread.php?tid=3154788#1 ignorant user: CLICK ME


