-1

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();
	}
	}
}
Votes + Comments
Learn how to post.
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ArkM
0

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...

This topic has been dead for over six months. 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.