Hi all. I am a begginer, just started in school learning this. Well, I have a problem in one of my assingments:
Code:// a game where the computer has to guess a number that the // user is thinking of. I am a beginnner, and I haven't learned // all the cool stuff yet - like using random number generator // so I am trying to do this the simple way. But this isn't working // properly, something about the numbers and the // guessing in the do-while loop. #pragma argsused #pragma argsused #include <iostream.h> #include <conio.h> using namespace std; int main() { int highNumb = 100; int lowNumb = 1; int guess; char ans; cout << "Think of a number between 1 and 100 \n"; cout << endl; guess =(highNumb+lowNumb)/2; cout << "is the number " << guess << " ?\n"; cout << endl; cout << "is the number correct or is it too high or too low? (c,h,l)\n"; cin >> ans; do { lowNumb = ++guess; guess = (highNumb + lowNumb)/2; cout << "the number is: "<< guess <<endl; cin >> ans; if (lowNumb >= highNumb) cout << "CHEATER!! " <<endl; }while (ans == 'H' || ans == 'h'); do { highNumb = --guess; guess = (highNumb - lowNumb) ; cout << "the number is: " << guess <<endl; cin >> ans; if (lowNumb >= highNumb) cout << "CHEATER "<<endl; }while (ans == 'L' || ans == 'l'); if (ans == 'R' || ans == 'r') cout << "GENIOUS!!!"<<endl; getch (); return 0; }



LinkBack URL
About LinkBacks
Hi all. I am a begginer, just started in school learning this. Well, I have a problem in one of my assingments:


