Programming questions yet again.
category: code [glöplog]
My dad used to say: "Son, don't run before you can walk". He was right, but that didn't stop me from trying. It's a symptom of being young and overestimating your own abilities, me thinks. :)
It can also be a symptom of being old and retarded beyond imagination, me thinks :P
Well, I'm old and I'm no longer trying to run before I can walk - I'm just lazy as fuck.
Trying to crawl before you are forced to run? I'm with you on that one :-)
Rowley you bugger but trc has leading. ;)
If you should run before you walk, you should lie around sucking tits for a year or so before you even think about walking.
Mmm, fresh from mother!
I'll forget how to walk, run, programm... if I can suck tits again :(.
I suppose I've always been like that. I've managed to get into an OpenGL tutorial and things are actually going well. :)
i wonder how different we would be if we were taught to suck our dad's cock milk as well our mother's breast milk.
Look, do I have to send you lot for a time out? :P
\o/ go 8-bit!!
Well someone had to. ;)
I've just completed my first program in C++, It's a bit of a mess, it's simple as hell. But hey, I'm enjoying myself. :D
I've just completed my first program in C++, It's a bit of a mess, it's simple as hell. But hey, I'm enjoying myself. :D
Code:
// Set up variables
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int guess,tries,target,perform_pick = 1;
char retry;
void check ()
{
tries = tries + 1;
if (target == guess)
congratulations ();
else
which_way ();
}
void which_way ()
{
if (target > guess)
cout << "Too high";
else if (target < guess)
cout << "Too low";
}
void congratulations ()
{
if (tries > 50)
{
cout << "Please don't play me again, you're embarassing yourself!";
try_again ();
}
if (tries > 30)
{
cout << "Meh! Don't tax your brain too much";
try_again ();
}
if (tries > 10)
{
cout << "Not bad, pretty good";
try_again ();
}
if (tries == 1)
{
cout << "OMFG! You're awesome! In one go aswell, you should be predicting lottery numbers!";
try_again ();
}
}
void picker ()
{
if (perform_pick == 1)
{
srand((unsigned)time(0));
target = (rand()%1000)+1;
perform_pick = 0;
}
else if (perform_pick = 0)
perform_pick = 0;
}
void try_again ()
{
cout << "Do you wish to try your luck again? Y/N\n";
cin >> retry;
if (retry == 'y')
{
perform_pick = 1;
picker ();
}
else if (retry =='n')
{
cout <<"Buhbye!";
system ("pause");
exit (0);
}
}
int main ()
{
picker ();
cout << "Guess a number between 1 and 1000\n";
cin >> guess;
check ();
system ("pause");
return 0;
}
Bugger! I found someone else that's done this, but this just seems too complex. Is there anyway of simplifying it? :S
The structure is definitely shot-to-fuck.
8-bit buggery: if youre using c++ then learn about classes. shouldn't take too long to learn. its a good way to wrap all functions inside object(s). its no good having global variables like that.
Was kinda thinking that. Cheers. :)
for your classes, you declare/define private or protected functions that you are only calling inside one function of the class and declare/define public functions that you wanna call from the main program. do the same for variables, actually all variables should be private unless you are working with inheritage. but i dont think you need to do that for this program.
I'm probably a bit conservative here, but I'd suggest learning about "loops" before going into object-anything :)
Global variables aren't anywhere near the biggest proglem there. Look at main() and - using only that information - try to tell how many guesses the program gives you.
Global variables aren't anywhere near the biggest proglem there. Look at main() and - using only that information - try to tell how many guesses the program gives you.
problem even
Code:
if (perform_pick = 0)
perform_pick = 0;
eh?
There's a bunch of other errors in there. Like if you take >50 guesses, it will print out all of the messages in congrats(). And "if (perform_pick == 0) perform_pick = 0", was that really worth typing? :D
Infact it's worse than that, it's not even ==!
216: globals dont simplify a damn thing. lol.
Code:
bool do_you_want_to_try_again()
{
print_do_you_want_text();
char retry;
cin << retry;
return retry == 'y' || retry == 'Y';
}
int main()
{
print_some_introduction_text();
int guess;
cin << guess;
int check = guess + 1;
while(guess != check)
{
print_need_check_text();
cin << check;
if(cin == check)
print_congrats();
else
if(do_you_want_to_try_again())
guess = check;
}
return 0;
}
without any compiling, written in pouet's BBS box.