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!

Recommended Answers

All 2 Replies

... gives me an error.

What error?

You using string without string header...

#include<string>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.