the problem here is it makes a random number for the first guess but then it just chooses that number over and over instead of picking a new number between comguessHigh and Low.
here's my code so far.
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
char again = 'y';
while (again == 'y')
{
srand(time(0));
int comguessHigh = 100;
int comguessLow = 1;
int thenumber = rand() % 100 + 1;
int tries = 0, guess;
do
{
cout << "enter a number." << endl;
cin >> guess;
tries += 1;
if (guess < thenumber)
{
cout << "\nthats to low.\n" << endl;
int comguess = rand() % (comguessHigh - comguessLow + 1) + comguessLow;
cout << "\nComperter guesses " << comguess << endl;
if (comguess < thenumber)
cout << "\ncomputers guess was to low.\n" << endl;
comguessLow = comguess;
if (comguess > thenumber)
cout << "\ncomputers guess was to high.\n" << endl;
comguessHigh = comguess;
if (comguess == thenumber)
cout << "\nSorry the computer guessed it." << endl;
}
if (guess > thenumber)
{
cout << "\nthats to high." << endl;
int comguess = rand() % (comguessHigh - comguessLow + 1) + comguessLow;
cout << "\nCompurter guesses " << comguess << endl;
if (comguess < thenumber)
{
cout << "\ncomputers guess was to low.\n" << endl;
comguessLow = comguess;
}
if (comguess > thenumber)
{
cout << "\ncomputers guess was to high.\n" << endl;
comguessHigh = comguess;
}
}
}while(guess != thenumber);
cout << "thats it you guessed it in " << tries << " tries." << endl;
cout << "\n Do you want to play again? (y/n)" << endl;
cin >> again;
}
cout << "\nOk mabye next time.\n" << endl;
system ("PAUSE");
return 0;
}
please help thank you.
I tried putting in the code from jas12745 and it worked one time so I shut it off and started it back up and now it picks a number and won't change it again. I don't get it?
I now this is probly stupid but I just started playing with c++ like a week ago should I click the debug button to test my programs or is there a better way?
Edited by CommittedC0der, 14 November 2009 - 09:17 AM.
Use the [code] tags.


Sign In
Create Account


Back to top









