Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The C code that I have so far: #include #define BOARD_SIZE 9 int main(){ setbuf(stdout, NULL); printf(Welcome to X Game! ); char player1_first[23]; char player1_last[23];

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

The C code that I have so far:

#include #define BOARD_SIZE 9

int main(){

setbuf(stdout, NULL);

printf("Welcome to X Game! ");

char player1_first[23]; char player1_last[23];

char k;

printf("Enter Player 1's first name: "); scanf("%s", player1_first);

printf("Enter Player 1's last name: "); scanf("%s", player1_last);

char player2_first[23]; char player2_last[23];

printf("Enter Player 2's first name: "); scanf("%s", player2_first);

printf("Enter Player 2's last name: "); scanf("%s", player2_last);

float score1; float score2;

//asking the two players to enter their scores and storing at their appropriate float variables printf("Enter Player 1's Score: "); scanf("%f", &score1);

printf("Enter Player 2's Score: "); scanf("%f", &score2);

//for the purpose of this assignment, a float variable "i" is defined //i takes a value entered by the user and stores it then it increments the two scores entered by the players by i float i;

printf("Enter size to increment scores by: "); scanf("%f", &i);

score1 = score1+i++; score2 = score2+(--i);

//printing the new incremented values for each player in a statement with the corresponding names printf("%s %s's Score: %.1f ",player1_first, player1_last, score1); printf("%s %s's Score: %.1f ",player2_first, player2_last, score2);

//This week's assignment: //a for-loop for the first, empty grid in the program //the first for-loop is for the first row of data since it starts with a space then 1-9 for(int x=0; x

printf(" ");

for(int x =1; x

for(int y = 1; y

}

printf(" ");

int x1, y1, x2, y2; //declaring variables for X-Y coordinates to be entered by both players do{ //a do-while loop to run the game

printf("Enter first X coordinate: "); scanf("%d", &x1);

printf("Enter first Y coordinate: "); scanf("%d", &y1);

printf("Enter second X coordinate: "); scanf("%d", &x2);

printf("Enter second Y coordinate: "); scanf("%d", &y2);

if(y1==y2)//using logic operators inside conditional statements //to see if the X-Y values entered by the players are aligned horizontally, vertically, or diagonally //if y1 equals y2 then the two points would be on the same horizontal line //a statement is printed either way starting with the two points are aligned in any way { printf("Horizontally Aligned = 1 "); } else printf("Horizontally Aligned = 0 ");

if(x1==x2) //if x1 equals x2 then the two points would be on the same vertical line { printf("Vertically Aligned = 1 "); } else printf("Vertically Aligned = 0 ");

if((x1!= x2)&&(y1!= y2)) //if x1 does not equal x2 AND y1 does not equal y2 then the two points would be aligned diagonally { printf("Diagonally Aligned = 1 "); } else printf("Diagonally Aligned = 0 ");

printf(" ");

for(int x = 0; x

printf(" ");

for(int x =1; x

for(int y = 1; y

}

printf("Enter an integer to continue (q to quit): "); //asking the user whether or not they want to quit the program by asking them to enter the an integer to continue or q to quit scanf("%s", &k);

}while(k != 'q'); //finally the programs stops after the user enters q //but it keeps running as long as the user does not enter q but enters anything else

return 0; }

This week you will be creating a couple of functions that wi ill he lp organize your code for the remaining weeks of the project. Start by creating macros for the different alignment types (horizontal, vertical, diagonal). Next create a function called "get Alignment" that uses the code you've already written to find the alignment of two points (this function should take in 2 points). Additionally, this function should return the alignment macros created earlier. Replace the code you copied with a call to the function instead. Next create a function called "printBoard" that uses the code you've already written to print a board with two points (this function should take in 2 points) Replace the code you copied with a call to the function instead. Create yet another function called "validatelnput" that gets the X or Y coordinate of a point with scan and validates the input. It should not take any parameters but return an integer. This function should be called at least 4 times per loop. Next, you may delete the code asking the user for each players scores, as well as how much to increment them by. Go ahead and set the starting score values to 2 for each player. Next create 2 macros, one for each player (e.g. #define PLAYER1 1 & #define PLAYER2 2). Then define an int variable in your main function to denote whose turn it is (This variable is used to save the 2 macros.). The starting value of this variable should be the player 1 macro. Use this variable in your game loop to print out whose turn it is. (See the following sample output for example)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions