Slot Machine

This is a discussion on Slot Machine within the C Programming forums, part of the General Programming Boards category; I made a slot machine some time ago, so... Would anyone take the time to mark it on a scale ...

  1. #1
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129

    Smile Slot Machine

    I made a slot machine some time ago, so...

    Would anyone take the time to mark it on a scale of 1 to 10?
    10 being perfect....and so on.

    And tell me ways to improve on it?

    I have in included a .exe for people who cant compile it with their compilers....i used Dev-Cpp 4.9.8.2 with added libraries, mainly conio....

    Thx,
    nomi.

    Zip file contains: slotcolour.cpp/.exe, slotnocolour.cpp/.exe and a readme.

    NOTE:ya colour is spelled with a u...i got my conio modified to take both spellings....

    EDIT:^^^^^^Yes I am canadian^^^^^^
    Attached Files Attached Files
    Last edited by nomi; 01-02-2004 at 02:35 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >fflush (stdin); // clear the keyboard buffer
    Change the comment to:
    Code:
    /* Do something either implementation-dependent if the compiler supports it, undefined otherwise */
    Or you could not use fflush on input streams, which is stated as having undefined behavior by the C standard. From a quick glance of the program that seems to be your biggest error, next being a failure to check return codes on interactive input. Also note that the // comments are C++ only unless your compiler is C99 compliant. If you don't know whether your compiler is C99, it probably isn't, so stick to /* */ comments.

    Why did you have two of the same program, the only difference being the use of color management? Conditional compilation or a command line option would probably be a better choice.

    >Would anyone take the time to mark it on a scale of 1 to 10?
    7, until I take the time to look at it more closely. The score may go up after that, but I wouldn't consider that likely judging how pedantic I am. I'll give you a list of improvements to make as well...when I have enough time, so probably later this afternoon.
    My best code is written with the delete key.

  3. #3
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    Originally posted by Prelude
    Also note that the // comments are C++ only unless your compiler is C99 compliant. If you don't know whether your compiler is C99, it probably isn't, so stick to /* */ comments.
    Dont knw about C99, but my compiler is Dev-Cpp 4.9.8.2.... So i dont know if I sometimes put in C++ code since it wont complain...
    Boolean (or) => C - || => C++ - OR

    I used fflush(stdin) to clear keyboard buffers...after using a scanf("",); my compiler renders getchar(); useless, So if want the user to press <enter>, the program takes it from the buffer rather than waiting for the user....or i really dont know what you mean by:
    Originally posted by Prelude
    Or you could not use fflush on input streams, which is stated as having undefined behavior by the C standard.
    Originally posted by Prelude
    Why did you have two of the same program, the only difference being the use of color management? Conditional compilation or a command line option would probably be a better choice.
    Yup i know that was a bit stupid, i was trying to make the program to compile without <conio.h> (using only C standard libraries) but then i needed it for clrscr(); and gotoxy(x,y);

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I used fflush(stdin) to clear keyboard buffers
    Click me!

    >after using a scanf("",); my compiler renders getchar(); useless
    All compilers do that because of the way scanf works. And getchar isn't useless, it just reads the crap that scanf left behind, making it seem useless. The scanf function is a messy creature, unless you want to clean up after it, don't use it. May I suggest looking at our FAQ?
    My best code is written with the delete key.

  5. #5
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    Originally posted by Prelude
    >I used fflush(stdin) to clear keyboard buffers
    Click me!

    >after using a scanf("",); my compiler renders getchar(); useless
    All compilers do that because of the way scanf works. And getchar isn't useless, it just reads the crap that scanf left behind, making it seem useless. The scanf function is a messy creature, unless you want to clean up after it, don't use it. May I suggest looking at our FAQ?
    Cool...now I can teach my teacher....thx

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Okay, here goes:
    Code:
    // Constants required by programme
    //----none----
    You don't need to say that the program doesn't use named constants. Their absence makes that point obvious.
    Code:
    // Function Prototypes -- alphabetical order
    Alphabetical order is nice, but order of importance is better. Or order of dependence. For example, if foo calls bar, and baz is a helper for both you could do this:
    Code:
    void baz ( void );
    void bar ( void );
    void foo ( void );
    Or take the opposite route and say that foo is the highest level function and bar and baz are mere helpers, so they aren't as important:
    Code:
    void foo ( void );
    void bar ( void );
    void baz ( void );
    Alphabetical order rarely makes the structure of the program clear. Coupled with good naming schemes, one of the above or something else would.

    >void decideOutcome(int*,int*,int*,int*,int*,int*,int*);
    Most of the time, that many parameters means your design needs work. Since the first five variables are slots, you can easily use an array instead. It's also a good idea to use parameter names even in your prototypes. Even though they aren't required, their presence does make understanding the code easier. Of course, this assumes well chosen names.

    >/* Variable Table
    I can't say as this is a good idea. It might be better to declare your variables on a single line followed by a descriptive comment instead.

    >int slot1,slot2,slot3,slot4,slot5;
    This would be easier to work with as an array.

    >//declaring floats (real values)
    I think we all know what floats are, perhaps something more descriptive as to the purpose instead of the mechanism.

    >//repitition structure to repeat tasks if certain are true (do.while loop).
    Once again, don't bother with mechanism. Even if you made the comment
    Code:
    // Keep taking the user's money until they're broke.
    it would be better than saying what is obvious, that here there be loops.

    >void decideOutcome(int* slot1,int* slot2,int* slot3,int* slot4,int* slot5,int* win,int* lose)
    Lose and win being pointers I can understand, but you don't write to any of the slots in this function. Making them pointers just clutters the syntax.

    >srand (time (0));
    This would better placed in main so that you only end up calling it once.

    >scanf ("%d",choice);
    Always check to make sure that the user isn't stupid. They too often are:
    Code:
    if ( scanf ( "%d", choice ) != 1 ) {
      /* Something wrong, bail */
      return 2;
    }
    /* Band-Aid for scanf, replaces fflush(stdin) */
    while ( getchar() != '\n' )
      ;
    >scanf("%f", bet);
    See above.

    >fflush (stdin);
    See above above.

    >void programmeInfo(void)
    You have an eight line comment to describe a three line function...

    There isn't anything really bad about your program, and nothing that a good perusal of K&R won't cure.
    My best code is written with the delete key.

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    Re: Slot Machine

    Zip file contains: slotcolour.cpp/.exe, slotnocolour.cpp/.exe and a readme.

    ya colour is spelled with a

    [^^^^^^Yes I am canadian^^^^^^
    nothing wrong with that!!! I AM CANADIAN!!

  8. #8
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    >Alphabetical order is nice, but order of importance is better. Or order of dependence. For example, if foo calls bar, and baz is a helper for both you could do this:

    My teacher wants me to keep it in alphabetical order so its easier for him to mark it....dunno why though???

    And I tried using arrays but i screwed up bad.....but i'm going to make another attempt now, it will fetch me more marks....btw i have to submit this so i prolly wont get time...but i will fix my comments.

    Thx for the tips....

    /me off to fix comments.

    ps. I have started planning on a database program which will keep a record of inventory for, say, Wal Mart......Once I make the programme.....you have to check it for me

    EDIT: K&R ???

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >K&R ???

    The C Programming Language by Brian Kernighan & Dennis Ritchie
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    UNIX chick
    Join Date
    Mar 2003
    Posts
    92
    Just a little note: <conio.h> is not platform independent. This mean i.e. that I can't compile the app (as I'm on OS X). This should at least be written in the readme file. Just my two cents, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  2. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 02:08 AM
  3. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  4. Designing State Machine
    By axon in forum Tech Board
    Replies: 3
    Last Post: 11-06-2003, 12:13 PM
  5. IDEA: A Slot Machine (aka a fruit machine)
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-13-2002, 12:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21