Alright so here's my question... I pretty much finished my little game I made, but I want to test to see if it works with a "debug cheat" to see if the program is actually showing you the right number.
I have srand(time(0)) set so that when you play the game, the program obviously makes the number selection different each time. Though, it apparently keeps generating a different number apparently, because the system time is changing.
As you can see in the code, I have a variable named "ANSWER" aka Range(low,high). The user input variable called "guessN" is checked to see if it matches "ANSWER". If it does, then the program says the user won the game, which I believe works.
The PROBLEM is that when I want the program so show what the answer is first, which happens to be 47, when I enter in 47, it's actually WRONG because the time generator is still going and it turned to be 37 already.
What I need help with: is there a way to currently pause the generation until the user enters in his answer?..
THANK YOU IN ADVANCE FOR HELPING ME! :)
SCREEN SHOT:
https://i.stack.imgur.com/CWAhw.png
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib> // For srand and rand
using namespace std;
/*Guessing Game: Program generates random #'s,
user has 3 chances to guess one number at a time,
otherwise the Computer wins.
*/
static unsigned int rangevalue;
void NewRange(int nLow, int nHigh) // Range for generated #'s.
{
rangevalue = (rand() % (nHigh - nLow + 1)) + nLow;
}
unsigned int getRange()
{
return rangevalue;
}
//DON'T GET LOST!
string DescRange; // Descriptive Range
string SelectionInput;
int low = 1;
int high;
//DON'T GET LOST!
void NumberGen()
{
do
{
cout << "Guess a number in between...\n " << endl;
cout << "1.) 1-5\t\t[EASY]" << endl;
cout << "2.) 1-10\t[MEDIUM]" << endl;
cout << "3.) 1-50\t[HARD]" << endl;
cout << "4.) 1-100\t[IMPOSSIBLE]" << endl;
cout << "\n5.) Choose a custom range? *" << endl;
cout << "6.) EXIT \n" << endl;
cout << "=> ";
getline(cin, SelectionInput);
} while (
SelectionInput != "1" && SelectionInput != "2" && SelectionInput != "3" && SelectionInput != "4" && SelectionInput != "5" && SelectionInput != "6"
&& SelectionInput != "EASY" && SelectionInput != "Easy" && SelectionInput != "easy"
&& SelectionInput != "MEDIUM" && SelectionInput != "Medium" && SelectionInput != "medium"
&& SelectionInput != "HARD" && SelectionInput != "Hard" && SelectionInput != "hard"
&& SelectionInput != "IMPOSSIBLE" && SelectionInput != "Impossible" && SelectionInput != "impossible"
&& SelectionInput != "CUSTOM" && SelectionInput != "Custom" && SelectionInput != "custom"
&& SelectionInput != "EXIT" && SelectionInput != "Exit" && SelectionInput != "exit"
);
if (SelectionInput == "1" || SelectionInput == "EASY" || SelectionInput == "Easy" || SelectionInput == "easy")
{
high = 5;
DescRange = "1-5";
cout<<"\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
}
else if (SelectionInput == "2" || SelectionInput == "MEDIUM" || SelectionInput == "Medium" || SelectionInput == "medium")
{
high = 10;
DescRange = "1-10";
cout<<"\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
}
else if (SelectionInput == "3" || SelectionInput == "HARD" || SelectionInput == "Hard" || SelectionInput == "hard")
{
high = 50;
DescRange = "1-50";
cout<<"\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
}
else if (SelectionInput == "4" || SelectionInput == "IMPOSSIBLE" || SelectionInput == "Impossible" || SelectionInput == "impossible")
{
high = 100;
DescRange = "1-100";
cout<<"\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
}
else if (SelectionInput == "5" || SelectionInput == "CUSTOM" || SelectionInput == "Custom" || SelectionInput == "custom")
{
cout<<"\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
cout << "Input a digit range for you to guess a number in between. " << endl;
cout << "Low: ";
cin >> low;
cout << "High: ";
cin >> high;
}
else if (SelectionInput == "6" || SelectionInput == "EXIT" || SelectionInput == "Exit" || SelectionInput == "exit")
{
high = 10;
cout << "\nYou've chosen to terminate the program!" << "\t[Input was \"" << SelectionInput << "\"]\n\n" << endl;
for (int iii = 0; iii < 5; iii++)
{
cout << "The program will now collapse..." << endl;
}
cout << "\n" << endl;
}
NewRange;
int ANSWER = getRange();
cout << "For debugging/test purposes, the range is: \"" << ANSWER << "\". \n" << endl; // DEBUG for knowing what the 'ANSWER' is.
}
void Guessing()
{
NumberGen();
int ANSWER = getRange(); // Making things SIMPLE
int guessN;
if (SelectionInput == "5" || SelectionInput == "CUSTOM" || SelectionInput == "Custom" || SelectionInput == "custom")
{
cout << "Guess the number I picked between " << low << "-" << high << ": ";
cin >> guessN;
if (guessN == ANSWER)
cout << "Oh no, you won! The answer \"" << guessN << "\", is... correct! \n\n" << endl;
else
cout << "\nSorry you lose, try again! Answer was " << ANSWER << ". \n\n" << endl;
}
else
{
cout << "Guess the number I picked between " << DescRange << ": ";
cin >> guessN;
if (guessN == ANSWER)
cout << "Oh no, you won! The answer \"" << guessN << "\", is... correct! \n\n" << endl;
else
cout << "\nSorry you lose, try again! Answer was "<<ANSWER<<". \n\n" << endl;
}
}
int main()
{
srand(time(0));
Guessing();
//system("PAUSE"); // * Temporarily Disabled *
return 0;
}