0

Hi!
I am trying to make a simple "Guess my number" game.
For some reason the compiler (Visual Studio 2010) gives me an error.
Here is the full code :

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

int main()
{
		int tries = 0;
		int input;
		srand(static_cast<unsigned int>(time(0)));
		int rand_number = rand() % 100	+ 1;
		string play_again;
		bool sucess;
	
	do{
	do {		
		cout << "Enter a number : " << endl;
		cin >> input;
		tries++;

		if (input > rand_number){
			cout << "Too high!" << endl;
		}else if (input < rand_number){
			cout << "Too low!" << endl;
		}else if (input == rand_number){
			cout << "You guessed it. It took you " << tries << " tries." << endl;
		}
	} while (input != rand_number);
		cout << "Do you wanna play aganin? (y/n)" << endl;
		cin >> play_again;
		if (play_again == "y")
			sucess = true;
	} while (!sucess);
	cin.get();
	return 0;
}

The problem is located here : } while (input != rand_number);
cout << "Do you wanna play aganin? (y/n)" << endl;
cin >> play_again;
if (play_again == "y")
sucess = true;
} while (!sucess);

I don't know what is the problem. Your help would be greatly appreciated. Thanks!

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vidit_X
0

You using string without string header...

#include<string>

Edited by vidit_X: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.