need help

Hi everyone,
if anyone is able to help greatly appreciated I am currently up to stage 4 and am hopeless with the loops, so if anyone can help from stage 4 onwards that would be amazing.


Stage 0 (preparation)
Start by setting up the project correctly. Please refer to the instructions on the course website if you are unsure of
how to do this.
At this stage, you will need to create a simple main() function (in the file called yourEmailId_game.c).
For example:
#include <stdio.h>
int main()
{
/* This line will eventually be removed – used for development purposes only. */
printf("\n\nProgramming assignment - this will be deleted in stage 1!\n\n");
return 0;
}
Make sure the program compiles and run the yourEmailId_game.c file. Once you have that working, back up your
project.



Stage 1
To begin, display the jackpot to the screen and prompt for and read the player’s choice. Display the player’s choice to
the screen as seen below.
Sample output 1:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal




Stage 2
Add code to generate the computer's choice.
Use the rand() function to simulate the computer’s choice (i.e. 1 + (rand() % 2) where 1 represents the
computer choosing steal and 2 represents the computer choosing deal). Display the computer's choice to the screen
as seen below.
Sample output 1:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal



Stage 3
Add code to determine whether the player wins, loses or draws with the computer. Display the appropriate message
to the screen according to the following rules of play:
 If both players (computer and human) choose to make a deal to share the jackpot, the jackpot is split equally
between both players and they both receive half the money. i.e. $50 each. The following message is
displayed to the screen: Draw! Split pot – 50 each!
 If the human player chooses steal the jackpot and the computer player chooses to make a deal to share the
jackpot, the human player receives all the money and the computer player who chose to make a deal receives
none. The following message is displayed to the screen: You win! You gain 100.
 If the computer player chooses steal the jackpot and the human player chooses to make a deal to share the
jackpot, the computer player receives all the money and the human player who chose to make a deal receives
none. The following message is displayed to the screen: You lose! Comp gains 100.
 If both players (computer and human) choose to steal the jackpot, they both receive nothing. The following
message is displayed to the screen: Too greedy! You get nothing!
Display the appropriate message to the screen as seen below:
Sample output 1:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal
Too greedy! You get nothing!



Stage 4
Now… it’s time to allow the player to play more than one game. Let’s add a loop which loops until the user either
enters 'q' (to quit the game) or the 10 game limit is reached. Think about where this code should go – what needs to
be repeated, etc.
Sample output 1:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Deal
You win! You gain 100.
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Steal
You lose! Comp gains 100.
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Deal
You win! You gain 100.
10 of 24
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Steal
You lose! Comp gains 100.
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Steal
You lose! Comp gains 100.
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal
Too greedy! You get nothing!
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal
Too greedy! You get nothing!
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Deal
Draw! Split pot - 50 each!
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Steal
You lose! Comp gains 100.
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Deal
You win! You gain 100.
Game limit reached.


Stage 5
Modify your code to keep a cumulative total of the winnings of both the player and the computer player.
 If both players (computer and human) choose to make a deal to share the jackpot, the jackpot is split equally
between both players and they both receive half the money. The split jackpot amount (i.e. $50 each) is added
to a cumulative total for both players.
 If the human player chooses steal the jackpot and the computer player chooses to make a deal to share the
jackpot, the human player receives all the money and the computer player who chose to make a deal receives
none. The jackpot amount is added to the cumulative total for the human player.
 If the computer player chooses steal the jackpot and the human player chooses to make a deal to share the
jackpot, the computer player receives all the money and the human player who chose to make a deal receives
none. The jackpot amount is added to the cumulative total for the computer player.
 If both players (computer and human) choose to steal the jackpot, they both receive nothing. The cumulative
total remains unchanged.
Display the results to the screen as seen below:
Sample output:
Jackpot: 100
Steal, Deal or Quit [s|d|q]? s
You chose: Steal
Comp chose: Steal
Too greedy! You get nothing!
>> Your score: 0 -- Comp score: 0 <<

Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Deal
Draw! Split pot - 50 each!
>> Your score: 50 -- Comp score: 50 <<
Jackpot: 100
Steal, Deal or Quit [s|d|q]? d
You chose: Deal
Comp chose: Deal
Draw! Split pot - 50 each!
>> Your score: 100 -- Comp score: 100 <<



Stage 6
Add code to keep track of how many games were played, won, lost and drawn. Display this to the screen (as seen in
the sample output at the end of this handout).


Stage 7
Add code to validate all user input:
 Steal, Deal or Quit [s|d|q]?
Sample output:
Steal, Deal or Quit [s|d|q]? e
Please enter either 's', 'd' or 'q'
Steal, Deal or Quit [s|d|q]? q


Stage 8
Add code to ensure that the user is not choosing to steal the jackpot three times in a row. If the human player
chooses to steal the jackpot twice in a row the following warning message is displayed to the screen: Careful… one
more steal and you lose it all! If the human player chooses to steal the jackpot three times in a row, the
following message is displayed to the screen: I told you so… you lose all of your winnings! In this
case, the cumulative total of the human player is set back to zero.



Stage 9
Modify your code to include and make use of the following two functions:
 void display_details(void);
 char get_menu_choice(void);
1. Write a function called display_details that will display your details to the screen. The function takes no
parameters and does not return a value. The function simply displays your details to the screen. Your
function should produce the following output (with your details).
Output:
File : wayby001_craps.c
Author : Batman
Stud ID : 0123456X
Email ID : wayby001
This is my own work as defined by the
University's Academic Misconduct Policy.
2. Write a function called get_menu_choice that displays the menu to the screen (Steal, Deal or Quit
[s|d|q]?), prompts for, reads and validates the menu command entered by the user. The function takes no
parameters and returns a valid menu command entered by the user.
For example:
user_player = get_menu_choice();
Reminder:
Defining a function does not execute the function – you will need to call the function(s) from the appropriate place(s)
from within the main function in the program (a particular function, more than once).




Stage 10
Now that you know your code is working – why not add code that will allow more randomness between runs.
To see more randomness between runs you can use the seed which is available as part of the C library. This seed
value gives the random number generator a new starting point. You can input any integer you like to this function as a
seed. Start your program by calling the time function (which returns the time of day in seconds) and passing the value
it returns to function srand() - this will seed the random number generator for you. You only need to do this once at
the start of your program.
For a different sequence each run:
#include <time.h>
srand(time(NULL));
It's generally a bad idea making a program without using helping functions. Maybe this homework is thought for realizing that. Here some helping hints for tackling your assignment:

Before you diving into coding, take some time for sketching a flow chart.

Use meaningful names for your variables, avoid something like 'a', 'u', 'x',

Make plenty comments to your code.

Good Luck.
If you've completed step 3, then you have a program that runs one game.

Stage 4 is putting that code in some kind of loop, that will allow you to run one game repeatedly. I'm not clear on why you're stuck.
Topic archived. No new replies allowed.