#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
int main() {
SetConsoleTitle("The Guessing Game!");
int guess;
int clue;
srand ( time(NULL) );
int num(rand() % 25 + 1);
int total;
cout << "Hello Internet\n";
Sleep(2000);
cout << "Today, we are going to play the Guessing Game!\n";
cout << "\n";
cout << "You are going to pick a number from 1-25 and if you need help\n" << "Id be happy to give you clues!\n" << "\n";
do
{
cout << "Pick a number: ";
cin >> guess;
cout << endl;
cin.ignore();
total++;
if ( guess < num ) {
cout << "Sorry, you guessed wrong!"<<endl;
cout << "Would you like a hint?\n" << endl << endl << "<y/n>";
char clue;
cin >> clue;
if ( clue =='y' ) {
cout << "You guessed low, sorry! Try again!\n";
}
}
else if ( guess > num ) {
cout << "Sorry, you guessed wrong!"<<endl;
cout << "Would you like a hint?\n" << endl << endl<< "<y/n>";
char clue;
cin >> clue;
if ( clue =='y' ) {
cout << "You guessed to high, sorry! Try again!\n";
}
}
else {
cout << "You won the game in" << total << "tries!" << endl;
}
} while ( guess != num );
cin.get();
return 0;
}
After the person gets the right number, the total that is displayed at the end of the program is some crazy number like 2068798 etc.. for the amount of tries it took to guess the right number, why is this?
Edit: OHHH lol, i think i see the problem, i didnt set the value of total in the beginning =(