First Year C++ help :(

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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 */

using namespace 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++;

}
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main(){

	char ch = 'y';

	while (ch == 'y'){
		std::cout << "Again y/n: ";
		std::cin >> ch;
	}
	return 0;
}
Topic archived. No new replies allowed.