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... ;)
aaaaahhhh fuck, just noticed my error...
should be "if(!do_you_want_to_try_again())" instead of "if(do_you_want_to_try_again())"
should be "if(!do_you_want_to_try_again())" instead of "if(do_you_want_to_try_again())"
also, my guess is entered by the user first :P ... blah, should be random of course
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)
Code:
do
{
if (guess > target)continue;
if (guess < target)continue;
else if (guess == target)break;
}while (guess != target);
not my type of logic
I'm still learning.