Really struggling with formatting my code to do the roll dice function. I really appreciate the answers I'm getting, but

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Really struggling with formatting my code to do the roll dice function. I really appreciate the answers I'm getting, but

Post by answerhappygod »

Really struggling with formatting my code to do the rolldice function.
I really appreciate the answers I'm getting, but I need this towork within my own code provided below.
Thank you for taking the time to look at the problem.
In C Programming Language onlyplease
1. Update a C source code file2. Use srand() function3. Use memset() function4. Use decision making5. Use arrays6. Pass arrays to functions7. Compile and run a file8. Submit to WebcoursesReferencesSource code examples in Webcourses1. dataTypes.c2. looping.c3. variables.c4. constants.c5. operators.c6. arrays.c7. decisionMaking.c8. functions.cTasksActivityboggle.c 1. Copy the C source code file from Assignment 2 andrename it forAssignment 32. Write the preprocessor command to include the time.h headerfilefrom the C library3. Write the preprocessor command to include the string.h headerfilefrom the C library4. After the #include preprocessor commands add the followingmacrosto create constants for the programa. DICE with the value of 16b. SIDES with the value of 6c. TRUE with the value of 1d. FALSE with the value of 0e. SPACE with the value of ' ' (i.e. there is ONE explicitspacebetween the open/close '; source code will not compilewithout the space)5. Update the function declaration or prototype for functiondisplayBoard6. Write the function declaration or prototype for functiondisplayDice7. Write the function declaration or prototype for functioncreateBoard8. Write the function declaration or prototype for functiongetLetter9. Update the main function to do the followinga. At the beginning of the main function, declare the followinglocal variables- i. Two-dimensional array (i.e. dice), data type character, size:16 rows, 6 columns (i.e. use the constants), initialized to thedata in Table 1 Boggle Data- ii. Two-dimensional array (i.e. board), data typecharacter, size:4 rows, 4 columns (i.e. use the constants)- iii. One-dimensional array (i.e. usedDie), data type integer,size: 16 columns (i.e. use the constants)b. Call function memset to initialize the usedDie array so allelements equal 0, passing the following arguments- i. usedDie array- ii. 0 (i.e. use the constants)- iii. sizeof(usedDie)c. Call function memset to initialize the board array so allelements equal an explicit space (i.e. ‘ ‘), passing the followingarguments- i. board array- ii. ‘ ‘ (i.e. use the constants)- iii. sizeof(board)d. Call function srand, pass as an argument function time(0)e. Comment out or delete the two consecutive functions callsa. displayExplicitBoard();b. clearScreen();f. Call function displayDice passing as an argument 2d arraydiceg. Call function clearScreenh. Call function createBoard, passing as argumentsa. 2d array diceb. 2d array boardc. 1d array usedDie- i. Call function displayBoard, passing as an argument 2d arrayboard10. Update function displayBoard to do the followinga. Update parameter list to include two-dimensional array (i.e.board), data type character, size: 4 rows, 4 columns (i.e. use theconstants)b. Comment out or delete local variables- i. num- ii. letterc. Output to the screen using function printf the first threerowsof the boggle boardd. Write a for loop to loop through the number of rows (i.e. useconstant ROWS)
- i. Write a for loop to loop through the number ofcolumns (i.e. use constant COLS)1. Comment out or delete the lines of code that
a. // generate the random numberb. // convert number to character based on decimal value2. Output to the console the character stored in the 2d array boardat the current row/col location11. Write function displayDice to do the followinga. Return type voidb. Parameter list includesi. Two-dimensional array (i.e. dice), data type character,size: 16 rows, 6 columns (i.e. use the constants)
c. Declare the following local variables- i. Data type integer (i.e. row)- ii. Data type integer (i.e. col)d. Write a nested for loop to loop through the 2d array dice- i. Output to the console the characters stored in the array12. Write function getLetter to do the followinga. Return type charb. Parameter list includes- i. Two-dimensional array (i.e. dice), data type character, size:16 rows, 6 columns (i.e. use the constants)- ii. Data type integer, (i.e. row)c. Declare the following local variables- i. Data type character (i.e. letter)- ii. Data type integer (i.e. col)d. Set variable col equal to randomly selecting a value from 0–5 (i.e. use the constants)e. Set variable letter equal to the element in the 2d array dice atthe row/col locationf. Return variable letter13. Write function createBoard to do the followinga. Return type voidb. Parameter list includes- i. Two-dimensional array (i.e. dice), data type character, size:16 rows, 6 columns (i.e. use the constants)- ii. Two-dimensional array (i.e. board), data type character,size: 4 rows, 4 columns (i.e. use the constants)- iii. One-dimensional array (i.e. usedDie), data type integer,size: 16 columnsc. Declare the following local variables- i. Data type character (i.e. letter)- ii. Data type integer, (i.e. row)- iii. Data type integer, (i.e. col)- iv. Data type integer (i.e. die)d. Write a loop to loop through the 4 rows (i.e. use the constants)of the board array- i. Initialize variable col to 01. While variable col is less than 4 (i.e. use the constants)a. Set variable die equal to randomly selecting a value from 0 – 15(i.e. use the constants)b. If the die has not been used (i.e. check the usedDie array atthe location)i - Set variable letter equal to function call getLetter, passingas arguments1. 2d array dice2. Local variable die- ii. Set array parameter board, at the current row/col location,equal to the value stored in variable letter- iii. Set array parameter usedDie, at the current die location,equal to 1 (i.e. use the constants)- iv. Increment the loop control variable
Boggle executableTest Case 1 Test Case 1 passesTest Case 2 Test Case 2 passesTest Case 3 Test Case 3 passesTest Case 4 Test Case 4 passesTest Case 5 Test Case 5 passesSource compiles with no warningsSource compiles with no errorsSource runs with no errorsSource includes comments
Perform the following test casesTest CasesAction Expected outcomeTest Case 1 Run executable When the executable runs, the output inthe command prompt should look like Figure 1Welcome screen function outputTest Case 2 User clicks the Enter keyThe screen is cleared of the welcome screenTest Case 3 The output in the command prompt should look similarFigure 2 displayDice functionoutput
Example:
Really Struggling With Formatting My Code To Do The Roll Dice Function I Really Appreciate The Answers I M Getting But 1
Really Struggling With Formatting My Code To Do The Roll Dice Function I Really Appreciate The Answers I M Getting But 1 (50.3 KiB) Viewed 12 times
My source file:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define ROWS 4
#define COLS 4
#define LETTERS 26
#define DICE 16
#define SIDES 6
#define TRUE 1
#define FALSE 0
#define SPACE ' '
void welcomeScreen();
// void displayExplicitBoard();
void clearScreen();
void displayBoard();
void displayDice();
void createBoard();
char getLetter(char [][SIDES],int );
int main()
{
char dice[DICE][SIDES] = {
{'I', 'O', 'S', 'S', 'E', 'T'},
{'D', 'R', 'L', 'X', 'E', 'I'},
{'C', 'P', 'O', 'H', 'S', 'A'},
{'N', 'H', 'N', 'L', 'Z', 'R'},
{'W', 'T', 'O', 'O', 'T', 'A'},
{'I', 'O', 'S', 'S', 'E', 'T'},
{'N', 'W', 'E', 'G', 'H', 'E'},
{'B', 'O', 'O', 'J', 'A', 'B'},
{'P', 'S', 'A', 'F', 'K', 'F'},
{'I', 'U', 'N', 'H', 'M', 'Q'},
{'Y', 'R', 'D', 'V', 'E', 'L'},
{'V', 'E', 'H', 'W', 'H', 'R'},
{'I', 'O', 'T', 'M', 'U', 'C'},
{'T', 'Y', 'E', 'L', 'T', 'R'},
{'S', 'T', 'I', 'T', 'Y', 'D'},
{'A', 'G', 'A', 'E', 'E', 'N'}};
char board[ROWS][COLS];
int usedDie[DICE];
memset(usedDie, 0, sizeof(usedDie));
srand(time(0));
welcomeScreen();
// displayExplicitBoard();
clearScreen();
displayBoard();
return 0;
}
void welcomeScreen()
{
printf(" ");
printf("BBBBB OOOO GGGGG GGGGG LL EEEEEE\n");
printf(" ");
printf("BB BB OO OO GG GG LL EE \n");
printf(" ");
printf("BBBBB OO OO GG GG LL EEEEE \n");
printf(" ");
printf("BB BB OO OO GG GGG GG GGG LL EE \n");
printf(" ");
printf("BBBBB OOOO GGGGG GGGGG LLLLLL EEEEEE\n");
printf("\n\n\n");
printf("Rules of the game:\n");
printf("\t\t1. The player is presented with a boggleboard.\n");
printf("\t\t2. The player will have three minutes to find asmany words as possible.\n");
printf("\t\t3. Words must contain three letters ormore.\n");
printf("\t\t4. Words are formed from adjoining letters.\n");
printf("\t\t5. Letters must join in proper sequence to spell aword.\n");
printf("\t\t6. Letters may horizontally, vertically, ordiaginally to the left, right, up or down.\n");
printf("\t\t7. No letter cube may be used more than once in asigle word.\n");
printf("\t\t8. words submitted will be scoredaccordingly.\n");
printf("\t\t9. Good luck!\n\n\n");
}
void displayExplicitBoard()
{
printf("\t|-------------------------------|\n");
printf("\t| BOGGLE BOARD |\n");
printf("\t|-------------------------------|\n");
printf("\t| T | A | O | C |\n");
printf("\t|-------------------------------|\n");
printf("\t| L | I | S | M |\n");
printf("\t|-------------------------------|\n");
printf("\t| U | N | B | I |\n");
printf("\t|-------------------------------|\n");
printf("\t| B | O | G | D |\n");
printf("\t|-------------------------------|\n");
}
void clearScreen()
{
char ch;
printf("\t\t\t\tHit <ENTER> to continue!\n\n\n");
scanf("%c", &ch);
system("cls");
}
void displayBoard()
{
int row, col, num;
char letter;
printf("\t|-------------------------------|\n");
printf("\t| BOGGLE BOARD |\n");
printf("\t|-------------------------------|\n");
srand(time(0));
for (row = 0; row < ROWS; row++)
{
printf("\t|");
for (col = 0; col < COLS; col++)
{
num = rand() % 26;
letter = 65 + num;
printf(" %c |", letter);
}
printf("\n\t|-------------------------------|\n");
}
}
void displayDice(char dice[DICE][SIDES])
{
int row;
int col;
for (row = 0; row < DICE; row++)
{
for (col = 0; col < SIDES; col++)
{
printf("%c", dice[row][col]);
}
}
}
char getLetter(char dice[DICE][SIDES], int row)
{
// Use current time as
// seed for random generator
srand(time(0));
int col = rand() % SIDES; // randomly selecting a value from 0 -5
char letter = dice[row][col];
return letter;
}
void createBoard(char dice[DICE][SIDES], char board[ROWS][COLS],int usedDie[DICE])
{
char letter;
int row;
int col;
int die;
for (row = 0; row < ROWS; row++)
{
col = 0;
while (col < COLS)
{
die = rand() % DICE;
if (die != usedDie[die])
{
letter = getLetter(dice, die);
board[row][col] = letter;
usedDie[die] = TRUE;
col++;
}
}
}
}
BOGGLE DICE Die 1 DRL XEI Die 2 CPOHSA Die 3 NHNL ZR Die 4 ΝΤΟΟΤΑ Die 5 I OSSET Die 6 NWEGHE Die 7 BOOJA B Die 8 UIENES Die 9 PSAFKF Die 10 I UN H M Q Die 11 YRD VEL Die 12 VEHWHR Die 13 I OTMUC Die 14 TYELTR Die 15 STITYD Die 16 AGA EEN Hit <ENTER> to continue!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply