Practice Assignment

(slots1.c)

Information

  1. Write a program that similates a slot machine with 3 slots. The player will start out with 100 points. Each time the player requests another spin, 3 random numbers (from 1 to 5) will be generated. If two of the slots are the same, the player will win 15 points. If all 3 are the same, the player wins 30 points. This continues until the player chooses to quit, or the player has less than 10 points left. (Each spin costs 10 points).

    Here is a sample output from the program:

    You start with 100 points. Each play costs 10 points.
    There are 3 slots, each contains 5 different values.
    If you get 2 of the same, you win 15 points.
    If you get 3 of the same, you win 30 points.
    Here we go!
    
     4  4  4
    BIG WINNER! You get 30 points!! You now have 120 points.
    
    Play again? (1=yes,0=no) 1
     1  4  4
    You win 15 points. You now have 125 points.
    
    Play again? (1=yes,0=no) 1
     2  4  4
    You win 15 points. You now have 130 points.
    
    Play again? (1=yes,0=no) 1
     2  2  2
    BIG WINNER! You get 30 points!! You now have 150 points.
    
    Play again? (1=yes,0=no) 1
     2  2  5
    You win 15 points. You now have 155 points.
    
    Play again? (1=yes,0=no) 1
     1  4  1
    You win 15 points. You now have 160 points.
    
    Play again? (1=yes,0=no) 0
    

    The program continues to run until the user types in 0 (zero) or runs out of points. You should use a do...while loop again.

    The name of the file should be slots1.c and the command to compile it will look like this:

    gcc -O -Werror -Wall -Wextra -ansi -pedantic slots1.c PRNG.c -o slots1
    

    Approximate number of lines of code: 30.

Notes

  1. You are not given a driver or main file. All code is in your slots1.c file.
  2. You don't have to handle invalid input. You only need to handle 0 and 1 as input.
  3. You should start out testing your code interactively. Once you've got it working as expected, use input and output redirection to test it:
    slots1 < input.txt > myoutput.txt
    
    using the correct names for the input and output files. You can make your own input files, as well.
  4. Since there is no driver, you will need to make sure that the PRNG is seeded. This is already done for you in the partial C file.
  5. Here is a partial C file for you to get started: HTML    Text
  6. Sample output: output.txt. You need to do this to generate it:
    slots1 < input1.txt > myoutput.txt
    slots1 < input2.txt >> myoutput.txt
    
    Pay attention to the redirection operators. Here are the input files: input1.txt and input2.txt

  7. Random number generator files (put these in the same directory as your C file)

For those that would like an additional challenge:

  1. Allow the player to choose how many points to start with.
  2. Have 5 slots instead of 3.
  3. With 5 slots, change the reward system (there is now 4 of a kind and 5 of a kind).
  4. Make the reward system based on how many points the player bets. Currently, the cost to play is always 10 points.
  5. Each slot has 5 different values. What happens to the odds if each slot has only 3 different values? 8 Different values?
  6. There are enough variations to keep you busy for days! (You have all of the C knowlege that is required.)