Trying to code a guess how many gumballs in the gumballs jar, kinda thing. There are two problems I keep getting:
- It's supposed to say if the guess is to high or to low but that only happens when i enter a number over 1000 and it says: Enter your guess: 1001 Too High!
Too Low!
Enter your guess:
- If you type a letter or phrase it goes haywire saying:
Enter your guess: Too High!
Too Low!
but it keeps saying that at about a couple hundred maybe even a thousand times a minute -.-
#include<iostream>
#include<ctime>
using namespace std;
int main(void)
{
int iGumballs;
int iUserguess;
int iGuesses = 0;
while(true)
{
system("CLS");
cin.clear();
iGuesses = 0;
srand(static_cast<unsigned int>(time(0)));
iGumballs = rand()%1000+1;
cout << "How many gumballs are in the gumball jar, you guess!" << endl;
do
{
cout << "Enter your guess: ";
cin>> iUserguess;
if(iUserguess > iGumballs)
{
cout << "Too High!" << endl << endl;
}
if(iUserguess > iGumballs)
{
cout << "Too Low!" << endl << endl;
}
iGuesses ++;
}while(iUserguess > iGumballs || iUserguess < iGumballs);
cout << "You guessed the right amount of gumballs! High Five!" << endl << endl;
cout << "You took" << iGuesses << " guesses" << endl << endl;
system("PAUSE");
}
return 0;
}