I have to make a program for a class assignment and it's a number guessing game and I believe I got the random number generator correct but I'm wondering how to make the program so if the user wins or loses they have the option to play again or not. I was going to try the goto code (with Beginning variable) but I'm not entirely sure about that. Anyone who can help?
My code isn't done and I'm no where close to be being done but this is what I have so far. Sorry if this is a lot of code, but if someone could help it'd be much appreciated.
#include <iostream>
#include <cstdlib> /* Using the C standard library for creating a random number generator. */
#include <ctime> /* using internal PC clock to select random numbers since time is constantly changing */
usingnamespace std;
int randNum, Guess;
/* randNum used to place the number that is randomly generated. Guess is used to place the user's integer guess */
int Counter = 1;
/*The declared variable for the counter for the while statement*/
char response, Y, N, Beginning;
/* response is used to allow Y or N to answer. Y and N are used for the user to choose an answer for response.
Beginning is used so the Goto function can loop the program again.*/
void main()
{
Beginning:
do
{
srand (time(0));
randNum = rand() % 100;
cout << "Please enter a number between 0 and 100." << endl;
}
while(Counter <= 20);
cin >> Guess;
switch (Guess)
{
case 1:
Guess == randNum;
cout << "You guessed correctly!" << endl;
cout << "Would you like to play again?" << "Please enter (Y/N)" << endl;
cin >> response;
if (response == Y)
{
goto Beginning;
break;
case 2:
Guess != randNum;
cout << "Please try again!" << endl;
}
Counter++;
}