Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59) Assignment #1 (10% weightage) Dice Game Implementation Problem Statement Specifications: You are to implement a dice...

1 answer below »
Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)

Dice Game Implementation
Problem Statement Specifications:
You are to implement a dice game in which the user rolls a pair of dice against the computer. The rules
of the game are as follows:

1) Generate one play. User roll a pair of dice first and then the computer will do the same.

2) The player rolls the pair of dice and sums up the face values. Outcomes:
• If the first roll sum is a 7 or 11, the player wins and return ‘0’
• If the first roll sum is a 2, 3 or 12, the player looses and return ‘1’
• If the sum is other number, player continue rolling the dice until the user get
Point Match (PM). PM is set at the first roll. To win, the player must continue
olling the dice until him/her either “makes the highest PM” or roll winning or
losing numbers

3) Create a betting amount on each game and ca
y the sum total of money left using a
global variable. Possibilities:
• Say a user starts the game with some default money and he/she can only
place a bet using multiple of $5
• If the user wins the game, it makes 3 times the bet
• If the user loses the game, it loses all the money he/she has bet
• You can decide if the user is able to place a bet every time it rolls the dice, or
every time it plays a new game.
• The money won can get ca
ied over to the next game
• If the bet money left is 0, the user can not place any more bets.
• When the user decides to finish playing, the amount won should be
displayed.

















Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)

The following demonstrates a few executions of the program:





Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)





Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)




Requirements:

In order to successfully complete this program and obtain all the marks, you will need to:

1) Define WON and LOST as macros in your program. Use the values of 0 for WON and 1 for LOOSE

2) Implement a function, with function prototype int rollDice( void ):
 rollDice( ) should use rand( ) to randomly generate a number between 1 – 6 and should
eturn the number generated by rand( )

3) Implement a function, with function prototype int playGame( void );
 When the player is ready to play, (s)he would use the key ENTER to roll the dice
 If the user wins in his/her first roll, congratulate the player and return with WON
 If the user looses in his/her first roll, return with LOOSE and apologize
 Let the user keep playing until (s)he wins / loses, give an appropriate massage and finish
the game with the last roll value.

4) Your main( ) should
 Call your function playGame( )


Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)

 Ask the user if (s)he wants to continue playing another game, keeping track of the
numbers of Games lost and won

 When the user decides to finish playing, display the number of wins and losses he/she
had.
 Give the user an appropriate message depending on the number of wins or losses (s)he
had while playing
 Return with a value of EXIT_SUCCESS

5) Your program should use at least once the conditional operator

6) Write a program must implement ALL the requirements, explicit and implicit, listed in the
“Problem Statement Specifications” above.

7) You must distribute your functions in a meaningful manner across multiple .c files. The .c files
should contain functions that represent sensible groupings of functionality

8) You must define .h files as appropriate

9) Each function must have a header comments that explain what it does, and
describe/explain its inputs (if any) and return value (if any)

10) You must submit makefiles for both codes along with terminal screenshots and text files
of your properly commented code.

11) Your program should present information to the user in clear way. In the output given, a table is
presented with the number of roll, the value of the first and second dice, the sum total of face
values of the dice and the points that the user needs to achieve.

12) Your program should compile with the flags -Wall -ansi –pedantic


Deliverables:
• Create a folder called algonquinUserID1_algonquinUserID2_A1 (e.g,
“mynam00123_yourna45678_A1”) that represents the two members of your team. Only
one submission per group is required. You must submit your .c files in the assigned
submission folder on BRS section 010 (activities  Assignments). We don’t need your
entire project folder.
• You will need to demo this code in your lab session, the week of March 15-19th, 2021.
During demonstration, you must be able to answer any questions related to the
assessment.




Winter 2021 CST8234 – C Programming XXXXXXXXXXDue Date: March 14th, XXXXXXXXXX:59)
Assignment #1 (10% weightage)

Marking Scheme

Item Penalty
Coding co
ectness (functions’ structure) is substandard 3 marks
Inappropriate and Inefficient Logic 5 marks
Other specification violations 2 marks
Defilements in regards to distribution of well-contained functions
etween files and makefile
5 marks
Missed demonstration 15 marks
Input validation is inacceptable 10 marks
Total Marks Achieved ___Out of 40.
    Problem Statement Specifications:
Answered 1 days After Mar 03, 2021

Solution

Vaishnavi R answered on Mar 05 2021
147 Votes
ass1/dicegame.c
#include #include #include #include int totalgames = 0;
int wingames = 0;
int cu
Amount = 50;
ool bet = false;
int rollDice();
int playGame(int *x, int *y);
int main()
{
int number = 0;
while (1)
{
printf(" ROLL THE DICE[ENTER] QUIT TO [q]\n");
printf("--------------------------------------------------------------------------------------------------------------------\n");
printf(" ROLL NUM \t DICE#1 \t DICE#2 \t TOTAL ROLL \t POINT MATCH \n");
printf("--------------------------------------------------------------------------------------------------------------------\n");

call the function
int x = playGame(&totalgames,&wingames);
if (x == 1 && bet == true)
{
cu
Amount += (3 * (5 * number));
}
else if (x == 0 && bet == true)
{
cu
Amount = 0;
}
printf("your remaining money is %d \n", cu
Amount);
char str[10];
printf("Another game?[y/n]");
scanf("%s", str);
if (str[0] == 'y' && cu
Amount > 0)
{
printf("Would you like to bet? [y/n] \n");
char c[10];
scanf("%s", c);
if (c[0] == 'y')
{
printf("you have $%d would you like to bet? [1-%d] \n", cu
Amount, (cu
Amount / 5));
scanf("%d", &number);
if (number >= 1 && number <= (cu
Amount / 5))
{
printf("You bet $%d \n", (5 * number));
}
else
{
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here