Guessing game code won't work

I am very new at programming and i am trying to make a guessing game. They are to guess a number between 1 and 1000, and if it is too low, then i ask them to try again and the same if it was too high. I am not sure why my code is not working it keeps coming up as an error "LINK : fatal error LNK1561: entry point must be defined"

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
  #include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
const int MAX_VALUE = 1000;
int main()
{
	cout<<"Welcome to Jackpot!"<<endl;
	srand((unsigned int)time(NULL));
	int randomnumber = rand() % MAX_VALUE;
	randomnumber = rand() % MAX_VALUE + 1;
	string guess= "";
	do
	{
		cout<<"Guess a number: "<<endl;
		cin>>guess;
		int counter = 0;
		while(guess == randomnumber)
		{
			if (guess > randomnumber)
			{
				cout<<"Too high!"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
			else if (guess < randomnumber)
			{
				cout<<"Too low!"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
			else if (guess == randomnumber)
			{
				counter = counter + 1;
				cout<<"Thats correct! It took "<<counter<<" guesses."<<endl;
			}
			else
			{
				cout<<"That is not a valid guess, nice try ;)"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
		}
	}
	system("pause");
	return 0;
}
Last edited on
line 6: no ; at end.

line 19: you're comparing a string to an integer. try changing line 13 to make guess an integer also.

line 45: no while() condition
I'm sorry for being such a newbie, but what do you mean by no while() condition?
don't be sorry.

line 14 you start a 'do' loop... the format for which is:

1
2
3
4
do
{
     // code
} while( some condition );


you have left off the while() part at the end.
Last edited on
It still says entry point must be defined :/
Is it because i am not doing that part correctly?
post your code as it is now. I don't get that error with the original post
Line 14 is a do statement. The do statement must be terminated by a while condition.
1
2
3
4
5
  bool done = false;
  do 
  {  // some statements
  }
  while (! done);  // <- while clause missing in your code 

i still haven't finished the while statement at the end but it is still coming up with that error
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
#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
const int MAX_VALUE = 1000;
int main()
{
	cout<<"Welcome to Jackpot!"<<endl;
	srand((unsigned int)time(NULL));
	int randomnumber = rand() % MAX_VALUE;
	randomnumber = rand() % MAX_VALUE + 1;
	int guess= "";
	do
	{
		cout<<"Guess a number: "<<endl;
		cin>>guess;
		int counter = 0;
		while(guess == randomnumber)
		{
			if (guess > randomnumber)
			{
				cout<<"Too high!"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
			else if (guess < randomnumber)
			{
				cout<<"Too low!"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
			else if (guess == randomnumber)
			{
				counter = counter + 1;
				cout<<"Thats correct! It took "<<counter<<" guesses."<<endl;
			}
			else
			{
				cout<<"That is not a valid guess, nice try ;)"<<endl;
				cout<<"Try again: "<<endl;
				cin>>guess;
			}
		}
	}
	system("pause");
	return 0;
}
it won't compile until there's a while() condition.

line 13: now you're trying to initialize the int with a string. try int guess = 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
while(true)
{
	if (guess==randNum)
	{
		cout << "you found the number!";
		break; // stop the loop
	}

	else
	{
		//...
	}
	
}
#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
const int MAX_VALUE = 1000;
int main()
{
cout<<"Welcome to Jackpot!"<<endl;
srand((unsigned int)time(NULL));
int randomNumber = rand() % MAX_VALUE;
randomNumber = rand() % MAX_VALUE + 1;
int guess;
do
{
cout<<"Guess a number: "<<endl;
cin>>guess;
int counter=0;
while(true)
{
if (guess > randomNumber)
{
counter= counter +1;
cout<<"Too high!"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
else if (guess < randomNumber)
{
counter= counter +1;
cout<<"Too low!"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
else if (guess == randomNumber)
{
cout<<"Thats correct! It took "<<counter<<" guesses."<<endl;
break;
}
else
{
cout<<"That is not a valid guess, nice try ;)"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
}
}while (guess);
system("pause");
return 0;
}

I made a number of changes. I got your counter working. I don't know how to submit with the line numbers sorry. Yours was the first post I came across after finish reading the tutorials =D
Last edited on
Okay i understand now. Thanks everyone for all your help!
Topic archived. No new replies allowed.