Question: please help me code my assignment in c++ The first image is the rules of the game, and the second image is what the task
please help me code my assignment in c++
The first image is the rules of the game, and the second image is what the task is




2 The Rules of the Game The simplified version of Pass the Pigs that we will implement can be played with any k players, such that 2 sks 10. The players are arranged in a cyclic fashion. The players will take turns rolling an asymmetrical die, affectionately named the pig, to earn points. Rolling the pig can result in it landing in any of the following positions: Rolling Side yields 0 points and immediately ends the current player's turn, resulting in the pig being passed to the next player in the ring of players. Assuming k players and 0-based indexing, the next player to go after player 0 is player 1. After player 1 is player 2. Who is the player after player k 1? That would be player 0. Rolling either Razorback or Trotter earns 10 points for the player. Rolling Snouter earns 15 points. Lastly, rolling Jowler earns 5 points. The game ends when any player has earned 100 or more points. To summarize, a player's turn consists of repeatedly rolling a die that has a chance of yielding Side (ending that player's turn), a chance of yielding Jowler, and a a { chance each of yielding one of Razorback, Trotter or Snouter. Any roll other than Side accumulates some number of points for the current player. So no decisions need to be made by any player, once the game starts. This is the Candy Land of dice games. You will implement the version of Pass the Pigs using the rules presented in $2, placing the implementation in the source code file pig.c. The structure of your program should follow these steps: 1. Prompt the user to input the number of players, scanning in their input from stdin. You will want to use scanf() for this. To scan an int from stdin: 1 int input = 0; 2 scanf("%d", &input); In the event that the user inputs anything other than a valid integer between 2 and 10 inclusive, print the following error to stderr informing them of improper program usage, then use the default value of 2 as the number of players: i fprintf(stderr, "Invalid number of players. Using 2 instead. In"); What are stdin and stderr? In UNIX, every process on creation has access to the following input/output (1/0) streams: stdin, stdout, and stderr. A running program is a process. stdin, or standard input, is the input stream in which data is sent to be read by a process. stdout, or standard output, is the output stream where data written by a process is written The last stream, stderr, or standard error, is an output stream like stdout, but is typically used for error messages. 2. Prompt the user to input the random seed for this run of Pass the Pigs. In the event that the user inputs anything other than a valid seed, print the following error to stderr informing them of improper program usage, the use the default value of 2022 as the random seed: 1 fprintf(stderr, "Invalid random seed. Using 2022 instead. "); 3. Set the random seed and make sure that each player starts off with 0 points. Note that it isn't made explicit how you keep track of each player's points. There are, of course, many ways to go about this. You are encour- aged to keep things simple, however. 4. Proceed around the circle starting from player 0. For each player: (a) Print out the name of the player currently rolling the pig. An array of player names that you must use will be provided in the header file names.h. Index 0 of this names array is the name of the player 0, index 1 is the name of the player 1, and so on and so forth. (b) Roll the pig, increasing the player's point count until they either win the game or the pig lands on one of its two sides. (c) If the player has greater or equal to 100 points, then the win the game and a congratulatory message is printed to stdout celebrating their achievement. (d) If the rolled pig lands on one of its two sides, then the player's turn ends and the next player in the circle gets to have their shot at rolling the pig. A working reference program, or binary, will be made available for you shortly. It is also in this repository that you will find the header file of player names, names.h. Makefile G214 Bytes Edit Web IDE Replace Delete 1 CC = clang CFLAGS = -Wall -Wpedantic -Werror - Wextra 2 3 4 all: pig 5 6 pig: pig.o $(CC) -o pig pig.o 7 8. 9 pig.o: pig.c names.h $(CC) $(CFLAGS) -c pig.c 10 11 12 clean: 13 rm -f pig pig.o 14 15 format: 16 clang-format -i -style=file *.{c, h} names.h 186 Bytes Edit Web IDE Replace Delete 1 #pragma once 2 0 m 3. { 4 5 6. 7 8 const char *names [10] = "Wilbur", "Charlotte", "John", "Fern", "Templeton", "Avery", "Homer", "Henry", "Dr. Dorian", "Aranea", }; 9 10 11 12. 13 14
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
