Thread: My best C++ Programs

  1. #16
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    cout << "Enter your bet->";
    cin >> bet;

    while (cin.fail())
    {
    cout << "Invalid input, please restate->";
    cin >> bet;
    }

    Should catch the program before it 'bottoms out'; I think
    I should elaborate.. if what the user enters is not compatable with the variable type in which it is to be stored.. you'll get that unexpected behavior.

    Someone should correct me on this If I'm wrong
    Last edited by Dual-Catfish; 02-17-2002 at 12:33 PM.

  2. #17
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    >>>Someone should correct me on this If I'm wrong

    You aren't....

    good job.
    Blue

  3. #18
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160

    Talking

    cool, im going to put that in there when i make my next proggy

  4. #19
    Unregistered
    Guest
    Originally posted by Paro
    cool, im going to put that in there when i make my next proggy
    dont say "proggy" makes you sound like an AOLER...

  5. #20
    PROGGY
    Guest

    PROGGY

    PROGGY PROGGY LOOK AT ME IM SAYING PROGGY

    IM SORRY I CANT HELP IT

  6. #21
    Registered User skyline's Avatar
    Join Date
    Dec 2001
    Posts
    49
    hi paro, yes you did a pretty good job for a first semester project. one thing that i would have liked you to have in the project, however, was to return to the main menu rather than quit the entire program after choosing and running a menu topic. then maybe you could have the option to quit the program from the main menu. another thing you could do for fun, which i think would be really cool, would be to show the spinning-effect of a slot machine on those numbers. that may be a little tough but it's possible. i didn't take a good look at your source but one way i can think of doing this is go ahead and first come up with a random sequence of numbers, then store them in an array. then you could output this initial array to the console, then increment each number, then make use of the '/r' (i think) escape sequence to be able to return to the beginning of the same line you just outputted and overwrite with the new array. of course everytime you increment each number in the array you would have to make sure they restart to 1 once they increment past 8. you could use some time delay to show the effect of the spinning numbers slowing down and finally make them stop and output the resulting array (you could implement a simple time delay with an empty for loop; and you would have to have the time delay periodically shorten to show the slowing down of "spinning"). note that this will yield "random" results since you initialize an array with "random" values, make them "spin" for some fixed amount of time and this will in turn yield your "random" result everytime.

    i don't know, just an idea if you're interested; but none the less great job and keep up the good work!

  7. #22
    Registered User skyline's Avatar
    Join Date
    Dec 2001
    Posts
    49
    actually i'm forgetting how a slot machine actually works. you don't need to slow down the "spinning" of the numbers. you just let them "spin" the same speed; but what you would need to do is stop a number from spinning one by one starting from the left.

  8. #23
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    I would have 5 million dollars without interest if I saved all my money for a hundred years! Wow... I better get started after buying some more mattresses to stuff my money into.
    Blue

  9. #24
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    skyline:

    actually, it isnt that hard i can do it, and i can make it so it slows down... but one thing i cant do is make it so it spins and then you can hit a button so it stops... but yea, ill make it next week when i come back to school, or if you want i can modift my cpp file so it does it, but i cant compile it til i go back to school

  10. #25
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Someone should correct me on this If I'm wrong
    Not wrong, but could be better. How about this?
    Code:
    if ( cin>>bet ) {
      // It worked, test for correct bet values
      // and play the game
    }
    else {
      // Didn't work, panic (but not really)
    Why test for whether or not cin failed when your if..else statement can do it for you?

    -Prelude
    My best code is written with the delete key.

  11. #26
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    nice programs paro

  12. #27
    Registered User skyline's Avatar
    Join Date
    Dec 2001
    Posts
    49
    Originally posted by Paro
    skyline:

    actually, it isnt that hard i can do it, and i can make it so it slows down... but one thing i cant do is make it so it spins and then you can hit a button so it stops... but yea, ill make it next week when i come back to school, or if you want i can modift my cpp file so it does it, but i cant compile it til i go back to school
    actually, for simplicity and also since a slot machine doesn't do it anyway, we don't have to include the slowing down of "spinning". we just stop each number from "spinning" one by one. also, we shouldn't require the user hitting the button to make each number stop anyway since with a slot machine we just pull the lever and the machine stops the numbers by itself (although giving the user the ability to stop the numbers him/herself would be kind of a cool idea as well, but as you state you can't do it at the moment; but later on you can check out multi-threaded programming which will give you the ability to do that).

    you can't compile till you get back to school? there are a lot of free compilers you can obtain and install (on your home pc) that are available on the net. go here for a windows version of emacs along with gcc, g++, and more...

  13. #28
    Registered User skyline's Avatar
    Join Date
    Dec 2001
    Posts
    49
    file attached is the slot machine that "spins" the numbers (using your existing code), this is just as an example you could use for some help (i used an empty for loop to delay time, i think you would usually want to make a library call of some sort since using a empty for loop for delaying time will vary from machine to machine).

    also, i got a "666" string once that deducted half my points; but also awarded me for a 3 of a kind!

    [edited]
    added zip instead containing an .exe
    [/edited]
    Last edited by skyline; 02-17-2002 at 06:51 PM.

  14. #29
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Nice Program Paro. One problem with the Allowence program tho... your math is off :-(. Say I enter $5.00 a week it is mathemeitically impossible for me to get 260.71 a year. You should take my weekly allowence and multiply by 52 to get the yearly amount. That should not give me a decimal number. The same problem with Centuries, and Millenium. Good program but check your math.

    Isometric
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  15. #30
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    That math problem may be because floats and doubles are approximations, and you gotta be careful when you use them. Theres a way to make them more accurate, I think the command is something to the tune of _asm finite. I don't use floats often because they cause problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 05:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 12:24 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM