Question
I have to change my program to have global arrays. in my program I have things implemented this: However, they must be assigned as global
I have to change my program to have global arrays. in my program I have things implemented this:
However, they must be assigned as global arrays. I need to change that where my if statements are.
The example I was given is this:
#define NUM_GOOSE_SPACES 3
Const int gooseSpaces[NUM_GOOSE_SPACES] = {7,11,15};
This must be done for goose, bridge, maze, and skull
THIS IS MY PROGRAM BELOW
#include
#include
#include
#define WON 0
#define LOSE 1
int rollDice(void);
int playGame(void);
int rollDice(void) {
return ((rand() % 6) + 1);
}
int playGame(void)
{
int dice_1 = 0;
int dice_2 = 0;
int dice_3 = 0;
int dice_4 = 0;
int humanPlayer;
int computerPlayer;
int humanSum = 0;
int computerSum = 0;
int humanTotal = 0;
int computerTotal = 0;
int result;
int point = 0;
time_t t;
bool playForPoint = false;
srand(time(&t)); // Initialize random seed
while(humanTotal
{
printf("ROLL THE DICE WITH [ENTER] ");
fgetc(stdin);
dice_1 = rollDice();
dice_2 = rollDice();
dice_3 = rollDice();
dice_4 = rollDice();
humanSum = dice_1 + dice_2;
computerSum = dice_3 + dice_4;
printf("Dice 1:%2d Dice 2:%2d : Total Dice Count:%2d ", dice_1, dice_2, humanSum);
printf("Dice 1:%2d Dice 2:%2d : Total Dice Count:%2d ", dice_3, dice_4, computerSum);
humanTotal = humanSum + humanTotal;
computerTotal = computerSum + computerTotal;
printf("Human on space : %2d ",humanTotal);
printf("Computer on space : %2d ", computerTotal);
if(humanTotal == 7 || humanTotal == 11 || humanTotal == 15)
{
printf("You landed on a Goose! You must move your piece an extra : %2d spaces ", humanSum);
humanTotal = humanTotal + humanSum;
printf("Human is now on space: %2d ", humanTotal);
}
if(computerTotal == 7 || computerTotal == 11 || cumputerTotal == 15)
{
printf("Computer landed on a Goose! Computer must move your piece an extra : %2d spaces ", computerSum);
computerTotal = computerTotal + computerSum;
printf("Computer is now on space: %2d ", computerTotal);
}
if(humanTotal == 6)
{
humanTotal = 12;
printf("You landed on Bridge! You must move your piece to space : %2d ", humanTotal);
}
if(computerTotal == 6)
{
computerTotal = 12;
printf("Computer landed on Bridge! Computer must move your piece to space : %2d ", computerTotal);
}
if(humanTotal == 13 || humanTotal == 20)
{
humanTotal = humanTotal - humanSum;
printf("You landed on the Maze! You must go back to your previous space : %2d ", humanTotal);
}
if(computerTotal == 13 || computerTotal == 20)
{
computerTotal = computerTotal - computerSum;
printf("Computer landed on the Maze! Computer must go back to your previous space : %2d ", computerTotal);
}
if(humanTotal == 23)
{
humanTotal = 0;
printf("You landed on the skull! You must return back to the beginning! You are now at space : %2d ", humanTotal);
}
if(computerTotal == 23)
{
computerTotal = 0;
printf("Computer landed on the skull! Computer must return back to the beginning! Computer is now at space : %2d ", computerTotal);
}
if (humanTotal > 24)
{
humanTotal = 24 / humanSum;
printf("You :Lhave gone past 24, and your place will be deducted");
printf("You are now on space : %2d ", humanTotal);
}
if (computerTotal > 24)
{
computerTotal = 24 / computerSum;
printf("You have gone past 24, and your place will be deducted");
printf("You are now on space : %2d ", computerTotal);
}
}
}
int main (void){
int result = playGame();
switch ( result )
{
case WON:
printf("You won the game. ");
break;
case LOSE:
printf("You lost the game. ");
break;
default:
printf("Something went wrong in the program. ");
break;
}
return 0;
}
Symbol Spaces Action goose 7, 11, 15 move your piece again by the same distance bridge go to space 12 maze 13,20 go back to your previous space skull 23 return to the beginningStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started