Hi, I have this "number game" which i just learned tonight ..It runs..but ,not without this warning box poping up, which says: "uninitialized local variable 'guess' used"...This confusing me because i know i did everything exactly like i was taught ...can you find/fix my problem abd explain please it'll be a blessing ...thankyou so much..

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

int main()
{
	int random;
	int guess;

	srand(static_cast<unsigned int>(time(0)));
	random = rand()%7+1;

	std::cout << "Guess my number! (1-7)\n";

	while (guess != random)
	{
		std::cin >> guess;
		std::cin.ignore();
	if (guess < random)
	{
		std::cout << "Too Low!!!\n";
	}
	if (guess > random)
	{
		std::cout << "Too High!!!\n";
	}
	if (guess == random)
	{
		std::cout << "You Won!!! My number was: "<< random << "\n";
		std::cin.get();
	}
	}
}
William Hemsworth commented: Learn how to post. -2

I don't understand why you don't understand... ;)
Line #15: unitialized variable guess is compared with random. Unitialized means that the value of this variabe is undefined: it's a garbage. You will get the value in the next statement!
Back to the Future game...
No comments...

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.