Guessing Game

Hi guys! I wrote a Guessing Game program for a class project and what I intend to do is as follows:

This Program is a Guessing Game! There is a number that you must guess between 1-100 and you have an infinite number of guesses. You can play as long as you want. Any number below 0 or above 100 will not be in range,
therefore you will have to try another number but it will count as a try.
If you guess the correct number, you will be notified as to how many
attempts you had. Select -1 to exit at any time. Have fun!

Unfortunately I keep getting these errors:

warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

fatal error C1075: end of file found before the left brace '{'

Can you guys help me get rid of the errors? Thanks a million in advance!


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(void) {
srand(time(NULL));

while(true) {
int number = rand() % 100 + 1;
int guess;
int tries = 0;
char answer;

while(true) {
cout << "Enter a number between 1 and 100 (" << 1000000 - tries << " tries left): ";
cin >> guess;

{
tries++;
}

if(guess == -1) {
cout << "Thanks for playing!\n" << endl;
break;
}

if(guess < 1) {
cout << "Out of Range! Try again.\n";
if(guess > 100) {
cout << "Out of Range! Try again.\n";
} else if(guess > number) {
cout << "Too high! Try again.\n";
} else if(guess < number) {
cout << "Too low! Try again.\n";
}


else {
cout<<"Congratulations!! " << endl;
cout<<"You got the right number in " << tries << " tries!\n";
}

cout << "Would you like to play again (Y/N)? ";
cin >> answer;


if(answer == 'n' || answer == 'N') {
break;
}

cout << "\n\nEnter anything to exit. . . " << endl;
cout << "Coded by Gbanawoman" << endl;
system ("PAUSE");
return 0;
}
Last edited on
yeh. I dont know how you manage to fuck up like this. But you're literally missing 3 brackets at the end of your program.

1
2
3
		}// bracket for the nested while-loop
	}//bracket for the while-loop
}// And the almighty bracket for your function, main. 


Add that, After

1
2
3
system ("PAUSE");
return 0;
}


Edit: Also please, put all your code between code tags <> - http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Thanks I appreciate it! Sorry I'm not as smooth as you would like with the code! I'm not that good at it yet.
Thanks to your help, I was able to debug it but now every value I input is basically causing the same output regardless:

"Enter a number between 1 and 100 (1000000 tries left):

What can I do to make the program work?

Your guessing game is far from being correct.

There are a bunch of code for guessing games out there. Read through this thread - http://www.cplusplus.com/forum/beginner/115091/

And google guessing game c++ for other codes. Try and fix your code here and there. Once you think you've done your best, post your code here again with code tags, and I'll help you out.
Topic archived. No new replies allowed.