pouët.net

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. :)
added on the 2010-07-12 14:37:07 by trc_wm trc_wm
It can also be a symptom of being old and retarded beyond imagination, me thinks :P
added on the 2010-07-12 15:01:37 by havoc havoc
Well, I'm old and I'm no longer trying to run before I can walk - I'm just lazy as fuck.
added on the 2010-07-12 15:15:40 by trc_wm trc_wm
Trying to crawl before you are forced to run? I'm with you on that one :-)
added on the 2010-07-12 15:44:05 by havoc havoc
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.
added on the 2010-07-12 15:49:09 by psonice psonice
Mmm, fresh from mother!
I'll forget how to walk, run, programm... if I can suck tits again :(.
added on the 2010-07-12 18:35:22 by hadesbox hadesbox
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.
added on the 2010-07-12 19:16:44 by button button
Look, do I have to send you lot for a time out? :P
\o/ go 8-bit!!
added on the 2010-07-13 00:17:27 by ferris ferris
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
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.
added on the 2010-07-14 16:55:11 by rudi rudi
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.
added on the 2010-07-14 17:06:38 by rudi rudi
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.
added on the 2010-07-14 17:24:38 by 216 216
problem even
added on the 2010-07-14 17:25:22 by 216 216
Code: if (perform_pick = 0) perform_pick = 0;


eh?
added on the 2010-07-14 17:36:39 by the_Ye-Ti the_Ye-Ti
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
added on the 2010-07-14 17:39:33 by psonice psonice
Infact it's worse than that, it's not even ==!
added on the 2010-07-14 17:40:43 by psonice psonice
216: globals dont simplify a damn thing. lol.
added on the 2010-07-14 17:42:27 by rudi rudi
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.
added on the 2010-07-14 17:56:09 by hcdlt hcdlt

login