pouët.net

Go to bottom

Programming questions yet again.

category: code [glöplog]
btw: those 'print_*'-functions i was just too lazy to think of some ubercool/uberleet text stuff... ;)
added on the 2010-07-14 17:57:03 by hcdlt hcdlt
aaaaahhhh fuck, just noticed my error...

should be "if(!do_you_want_to_try_again())" instead of "if(do_you_want_to_try_again())"
added on the 2010-07-14 17:58:16 by hcdlt hcdlt
also, my guess is entered by the user first :P ... blah, should be random of course
added on the 2010-07-14 17:59:28 by hcdlt hcdlt
Code: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main () { int target; char retry; srand ((unsigned)time (0)); do { int guess = 0; int tries = 0; target = (rand()%1000)+1; do { tries ++; cout << "Guess a number between 1 and 1000: "; cin >> guess; if (guess > target) { cout << "Too high, try again!\n\n"; continue; } if (guess < target) { cout << "Too low, try again!\n\n"; continue; } else if (guess == target) { cout << "You did it in " << tries << " tries!\n\n"; if (tries >= 30) { cout << "Please don't play me again, you're embarassing yourself!\n\n"; break; } if (tries >= 10) { cout << "Meh! Don't tax your brain too much\n\n"; break; } if (tries >= 1) { cout << "Not bad, pretty good\n\n"; break; } if (tries == 1) { cout << "OMFG! You're awesome! In one go aswell, you should be predicting lottery numbers!\n\n"; break; } } }while (guess != target); cout << "Would you like to try again? (Y/N): "; cin >> retry; cout << endl; }while (retry == 'y'); return 0; }


Hah, I cross referenced the code. I can see all the mistakes I've made. This runs better, though you may find more mistakes. Cheers guys.
now try real c++ (with OOP)
added on the 2010-07-14 18:43:11 by hcdlt hcdlt
Code: do { if (guess > target)continue; if (guess < target)continue; else if (guess == target)break; }while (guess != target);


not my type of logic

added on the 2010-07-14 19:10:10 by the_Ye-Ti the_Ye-Ti
I'm still learning.

login

Go to top