Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Continue this assignment using the code and follow the intructions below #include //This is a statement which tells the compiler to insert the contents of

Continue this assignment using the code and follow the intructions below

#include //This is a statement which tells the compiler to insert the contents of stdio at that particular place. #include // This is the standard library in c programming #define BOARD_SIZE 9 void printboard(char array[][BOARD_SIZE]); // Prototyping a function and initializing it. char array[BOARD_SIZE][BOARD_SIZE]; int x,y,x1,x2,y1,y2; int horizontal,vertical,diagonal; char ch;

int main(void) //This is basically just the name of main function which is predefined function in C library and void implies no input arguments.

{ float player_1_score; // This declaring the player 1 score as a float. float player_2_score; // This declaring the player 2 score as a float. float increment; // This declaring the increment score as a float.

char player_1_first_name[20]; // returns the character value player 1 first name char player_1_last_name[20]; // returns the character value char player_2_first_name[20]; // returns the character value char player_2_last_name[20]; // returns the character value

setbuf(stdout,NULL); // used for windows

printf("Enter player1's first name?:"); // Prompt user to enter player 1 first name scanf("%s",player_1_first_name); //scanf reads the input value and saves it. printf("Enter player1's last name:"); // Prompt user to enter last name scanf("%s", player_1_last_name); //scanf reads the input value and saves it printf("Enter player2's first name"); // Prompt user to enter first name scanf("%s", player_2_first_name); //scanf reads the input value and saves it. printf("Enter player2's last name"); // prompt user to enter player 2 first name. scanf("%s", player_2_last_name); // scanf reads the input value and saves it.

printf("Enter player1's score"); // prompts user to enter player'1s score. scanf("%f", &player_1_score); //scanf reads the input value and saves it.

printf("Enter player2's score"); // prompts user to enter player2's score. scanf("%f", &player_2_score); //scanf reads the input value and saves it.

printf("Enter size to increment scores scores by:"); // prompts user to enter the size to increment scores scanf("%f", &increment); //scanf reads the input value and saves it.

player_1_score = player_1_score + increment; // Mathematical operation which shows the addition of the increment to player1's score player_2_score = player_2_score + increment; // Mathematical operation which shows the addition of the increment to player1's score

printf("%s %s's score is: %.1f ", player_1_first_name, player_1_last_name,player_1_score); // The output on the screen given by print f printf("%s %s's score is: %.1f ", player_2_first_name, player_2_last_name,player_2_score); // The output on the screen given by print f

while(1) // This means the loop { //fill the board with . for(x=0;x

printboard(array); //print the board

printf(" Enter first X coordinate : "); // Prompts user to enter the first X coordinate scanf("%d",&x1); //scanf reads the input value printf(" Enter first Y coordinate : "); scanf("%d",&y1); //scanf reads the input value printf(" Enter second X coordinate : "); scanf("%d",&x2); // scanf reads the input value printf(" Enter second Y coordinate : "); scanf("%d",&y2); //scanf reads the input value

array[y1-1][x1-1]='X'; // replacing the dot by x and filling the board on the input array[y2-1][x2-1]='X';

if(x1==x2) // The test if it is vertically aligned vertical=1; else vertical=0; if(y1==y2) // The test if it is horizontally aligned horizontal=1; else horizontal=0;

if(x1+y1==x2+y2 || abs(x1-y1)==abs(x2-y2)) //The test if it is diagonally aligned diagonal=1; else diagonal=0;

printf(" Horizonatlly Alligned = %d",horizontal); // The code determines the number associated with the horizontal printf(" Vertically Alligned = %d",vertical); // The code determines the number associated with the horizontal printf(" Diagonally Alligned = %d",diagonal); // The code determines the number associated with the horizontal

printboard(array); //The code prints out the result board

printf(" Enter an integer to continue(q to exit)"); // Prompts the User to enter an integer fflush(stdin); // flushes the output ch=getchar(); // gets the character if(ch=='q') // if condition break; // since running a while 1 loop we need a break point } return 0; // exit code }

void printboard(char array[][BOARD_SIZE]) // Prints the board size on the output

{ int x,y; // separate function and needs a new initialization printf(" "); // new line statement for(x=1;x

image text in transcribed

#include //Standard Library

#include

//Board Size Constant

#define BOARD_SIZE 9

//Player CONSTANTS

#define PLAYER1 1

#define PLAYER2 2

//Alignment Constants

#define HOR_ALIGN 3

#define VERT_ALIGN 4

#define DIAG_ALIGN 5

int getAlignment(int, int, int, int); //Returns Alignment Constant

void printBoard(int, int, int, int); //Prints Game Board

int validateInput();

For this assignment, re-use your Half-Semester Project (Week 20 source file (You may copy and paste the source code to a new project) Add the additional functionality described below: This week you will be creating a couple of functions that will help 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 getAlignment 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 scanfO 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

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions