I need help with my code please :/

its not compiling and I'm not sure why.




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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main (void)
{
	int AskRange;
	int GetMagicNumber = rand() % AskRange + 1;
	int Guess;
	int tries = 0;
        char PlayAgain;

	cout << " Please enter the top number of the range(Must be a number greater than 0) \n";
	cin >> AskRange;
	 
	if ( AskRange > 0 )
	{
		cin >> AskRange;
	}
	else
			
	{ 
		cout << " Please enter a value that is greater than zero \n";
		cin >> AskRange;

	}
	srand(time(NULL));

	while (true)
	{
		cout << " Enter a Number between 0 and " << AskRange << " ( " << 5 - tries << " tries left): \n";
		cin >> Guess;
		cin.ignore();

		if ( Guess > GetMagicNumber)
		{
			cout << " Too high! Try again.\n";
		}
		else if ( Guess < GetMagicNumber )
		{
			cout << " Too Low! Try Again.\n";
		}
		else
		{
			break;
		}
		tries++;
	}
	if (tries >= 5)
	{
		cout << " You ran out of tries!\n";
	}
	else
	{
		cout << " Congratulations!! " << endl;
		cout << " You got the right number in " << tries << "tries!\n";
	}
	while (true)
	{
		cout << " would you like to play again? ( Y/N)?" ;
		cin >> PlayAgain;
		cin.ignore();

		if ( PlayAgain == 'N' || PlayAgain == 'n' || PlayAgain == 'y' || PlayAgain == 'Y' )
		{
			break;
		}
		else
		{
			cout << " Please enter \'Y'\ or \ 'N'\ . . . \n";
		}
	}

	if ( PlayAgain == 'n' || PlayAgain == 'N' )
	{
		cout << "Thanks for playing!";
		break;
	}

cout << "Enter anything to exit. . . \n";
cin.ignore();
return(0);
}


EDIT**
Im getting so many errors, idk if i should post them all.
Last edited on
Hey. Please Edit your post and use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/

Whats not compiling? Please provide the errors you get. Copy paste them.
Last edited on
Hello! Looks like you're missing some syntactical things, they're easy to mess up when you're first starting. Some things to get you started.

1. make sure you have the >> operator after cin pointing the right direction every time
2. make sure cin.ignore is spelled right
3. make sure you declare all of your variables before using them (especially the guess variable)
4. you have an extra } somewhere near the end of your code
5. endl has an L at the end, not a 1
alright so , i made the fixes you were talking about i hope, kind of embarrassing that i messed up on those.

but i still don't see what you mean by the declaring part ;/
C++ is case sensitive so guess and Guess are different and guess is undeclared while Guess is undefined oh and error checking with an if statement may not be as good as using a loop
Last edited on
As in

int Guess{0};

Edit: I guess I missed the typo you made ;(

Gets coat....
Last edited on
As in int guess = 0;
Or by simply using the Guess variable and making the two "guess" into "Guess" which they should have been.
i switched the typo, but I'm still getting these errors:

error c2065 'end' undeclared identifier
'PlayAgain '


illegal breaks
syntax errors
Topic archived. No new replies allowed.