SlideShare a Scribd company logo
Connect4.c
2. Include the string.h header file
3. Declare the following macros (i.e., use #define NOT const) to use
as global constants for the application
a. ROW with a value of 6
b. COL with a value of 7
c. ONE with a value of 1
d. TWO with a value of 2
e. SPACE with a value of ' ' (NOTE: there is an explicit
space between the open and close single quote)
f. TRUE with a value of 1
g. FALSE with a value of 0
4. Write the function declaration or prototype for functions
a. initializeBoard
b. displayBoard
c. makeMove
5. Update function playGame to do the following
a. Add local variable named board, data type character,
two-dimensional array, size 6 rows and 7 columns (i.e.,
use macros ROW and COL)
b. Before the while loop
i. Call function initializeBoard; pass as an argument
array board
c. Inside the while loop
i. Comment out or delete call to function
displayExplicitBoard
ii. Call function displayBoard; pass as an argument
array board
iii. Inside the if/else if statements
1. Replace the printf statement notifying the
player it is their turn with call to function
makeMove; pass as arguments
a. Character array of players name
(i.e., yellow or red)
b. 2-d array board
6. Write function initializeBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Set the element at the current row and column in
the 2-d array board to an explicit space (i.e., use
macro SPACE)
7. Write function displayBoard to do the following
a. Return type void
b. Parameter list includes 2-d character array (i.e., board),
size 6 rows and 7 columns (i.e., use macros ROW and
COL)
c. Write printf statements to display the top row of the
Connect Four board
d. Write a nested for loop to iterate through the rows and
columns of array board to do the following
i. Write a printf statement to display the value
stored in the current element of the array board
8. Write function makeMove to do the following
d. Return type void
e. Parameter list includes
i. Character array for the players name (i.e.,
playerName, size is 20, use macro NAME)
ii. 2-d character array (i.e., board), size 6 rows and 7
columns (i.e., use macros ROW and COL)
f. Declare variable to store the user input for their move,
data type character array, size 2 (i.e., move, use macro
TWO)
g. Declare variable to store if player move is valid, data type
integer, initialize to 0 (i.e., valid, use macro FALSE)
h. Loop while the players move input is not valid (i.e.,
FALSE)
i. Write a printf statement to prompt the player to
enter their move
ii. Write a scanf statement to store the players move
in local variable move
iii. Write a printf statement to display to the player
the move they entered
iv. Declare variable to store the length of the players
move input, data type integer (i.e., length) set
equal to explicit type cast to integer of return value
from function call strlen(), pass as an argument
variable move
v. Evaluate variable length
1. If it is equal to 1, set variable valid equal to
true (i.e., use macros ONE and TRUE)
2. If it is not equal to 1, set variable valid
equal to false (i.e., use macros ONE and
FALSE)
vi. Evaluate variable valid, if it is false, write a printf
statement to notify the player their move input was
not valid (i.e., use macro FALSE)
Above are the instructions I need and below is what I currently have.
#include
#include
// global constants a.k.a. macros
#define NAME 20
#define YELLOW 1
#define RED 2
#define ZERO 0
#define FOUR 4
// function prototypes
void welcomeScreen ();
void displayEmptyBoard();
void playGame();
// main function
int main()
{
// call function welcomeScreen
welcomeScreen();
// call function displayEmptyBoard
// displayEmptyBoard();
// call function playGame
playGame();
// program executed successfully
return 0;
}
// welcomeScreen function displays the Connect Four logo and rules of the game
void welcomeScreen ()
{
printf (" CCCC OOOO N N N N EEEEE CCCC TTTTT FFFFF OOOO U
U RRRR n");
printf ("C O O N N N N N N EE C T F O O U
U R R n");
printf ("C O O N N N N N N EEEE C T FFF O O U
U R R n");
printf ("C O O N NN N NN EE C T F O O U
U R R n");
printf (" CCCC OOOO N N N N EEEEE CCCC T F OOOO UUUU
R R n");
printf ("n");
printf ("CONNECT FOUR GAME RULESnn");
printf("t 1. The board is 6 rows and 7 columns.n");
printf("t 2. The player with the yellow discs goes first.n");
printf("t 3. Players drop 1 disc in the grid at a time.n");
printf("t 4. Players alternate turns.n");
printf("t 5. Once a player has four discs in a row vertically, horizontally or
diagonally, they have won the game!n");
}
// function displayEmptyBoard displays a hardcoded version of an Connect Four board
void displayEmptyBoard()
{
printf("|------------------------------------------n");
printf("| A | B | C | D | E | F | G |n");
printf("|------------------------------------------n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
printf("| | | | | | | |n");
printf("|------------------------------------------n");
}
void playGame()
{
// store player names
char yellow[NAME]; // Karin
char red[NAME]; // Lia
// yellow (Y) always goes first
int currentPlayer = YELLOW;
int loop = ZERO;
printf("Player Yellow, please enter your namen");
scanf("%s", yellow);
printf("Player Red, please enter your namen");
scanf("%s", red);
printf("%s and %s, let's play Connect Four!n", yellow, red);
while(loop < FOUR)
{
// call function displayEmptyBoard
displayEmptyBoard();
// switch players for each move
if(currentPlayer == YELLOW)
{
printf("%s, it is your turnn", yellow);
// switch players
currentPlayer = RED;
}
else if(currentPlayer == RED)
{
printf("%s, it is your turnn", red);
currentPlayer = YELLOW;
}
loop++;
}
}
Please provide code screenshots in C language. Thank you

More Related Content

PPTX
C programming language tutorial
PDF
Game Design and Development Workshop Day 1
PPTX
programming language in c&c++
PPTX
C++ Programming Homework Help
PPTX
golang_getting_started.pptx
PDF
15646254 c-balaguruswamy-solved-programs
PPT
ch08.ppt
C programming language tutorial
Game Design and Development Workshop Day 1
programming language in c&c++
C++ Programming Homework Help
golang_getting_started.pptx
15646254 c-balaguruswamy-solved-programs
ch08.ppt

Similar to Connect4.c2. Include the string.h header file3. Declare the foll.pdf (20)

PDF
Please help with this. program must be written in C# .. All of the g.pdf
DOCX
C cheat sheet for varsity (extreme edition)
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
PDF
The following is my code for a connectn program. When I run my code .pdf
PPS
C programming session 01
PDF
Revision1 C programming
DOCX
Objectives Create a Java program using programming fundamentals (fi.docx
PDF
46630497 fun-pointer-1
PPTX
UNIT 6structureofcprogrammingforppt.pptx
PDF
Memory Management for C and C++ _ language
PDF
Java Question-Bank-Class-8.pdf
PDF
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
PPTX
Computer Network Assignment Help
PDF
Introduction to Input/Output Functions in C
PPTX
Lecture 04 Programming C for Beginners 001
PDF
C++ How to Program 10th Edition Deitel Solutions Manual
PDF
2 data and c
PDF
Managing I/O in c++
PDF
Core c sharp and .net quick reference
PDF
Core csharp and net quick reference
Please help with this. program must be written in C# .. All of the g.pdf
C cheat sheet for varsity (extreme edition)
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
The following is my code for a connectn program. When I run my code .pdf
C programming session 01
Revision1 C programming
Objectives Create a Java program using programming fundamentals (fi.docx
46630497 fun-pointer-1
UNIT 6structureofcprogrammingforppt.pptx
Memory Management for C and C++ _ language
Java Question-Bank-Class-8.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Computer Network Assignment Help
Introduction to Input/Output Functions in C
Lecture 04 Programming C for Beginners 001
C++ How to Program 10th Edition Deitel Solutions Manual
2 data and c
Managing I/O in c++
Core c sharp and .net quick reference
Core csharp and net quick reference
Ad

More from shakilaghani (11)

PDF
Directions Match Section A with Section B compete for cucumbers .pdf
PDF
Discuss the difference between the use of views and Transact-SQL sta.pdf
PDF
Culture Change at IBMIBM began in 1914 as a maker of cheese slicer.pdf
PDF
Create Your Brand Vision The first step to creating your personal bra.pdf
PDF
Create an excel file consisting of ten students� names in the follow.pdf
PDF
Compare and contrast indian culture with arab culture on the.pdf
PDF
Client A Moved from one side of the city to another and transitione.pdf
PDF
Choose the appropriate contraint type for what is descibed Field, T.pdf
PDF
Chapter 13 1. What is ontology 2. What is Realism 3. What is.pdf
PDF
ces ions mitochondria away from toward water thermoregulation osmore.pdf
PDF
Case Study Management Information System at Dell Management infor.pdf
Directions Match Section A with Section B compete for cucumbers .pdf
Discuss the difference between the use of views and Transact-SQL sta.pdf
Culture Change at IBMIBM began in 1914 as a maker of cheese slicer.pdf
Create Your Brand Vision The first step to creating your personal bra.pdf
Create an excel file consisting of ten students� names in the follow.pdf
Compare and contrast indian culture with arab culture on the.pdf
Client A Moved from one side of the city to another and transitione.pdf
Choose the appropriate contraint type for what is descibed Field, T.pdf
Chapter 13 1. What is ontology 2. What is Realism 3. What is.pdf
ces ions mitochondria away from toward water thermoregulation osmore.pdf
Case Study Management Information System at Dell Management infor.pdf
Ad

Recently uploaded (20)

PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Computing-Curriculum for Schools in Ghana
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Complications of Minimal Access Surgery at WLH
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Presentation on HIE in infants and its manifestations
Chinmaya Tiranga quiz Grand Finale.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Computing-Curriculum for Schools in Ghana
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Cell Types and Its function , kingdom of life
A systematic review of self-coping strategies used by university students to ...
human mycosis Human fungal infections are called human mycosis..pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
102 student loan defaulters named and shamed – Is someone you know on the list?
Complications of Minimal Access Surgery at WLH
Anesthesia in Laparoscopic Surgery in India
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Presentation on HIE in infants and its manifestations

Connect4.c2. Include the string.h header file3. Declare the foll.pdf

  • 1. Connect4.c 2. Include the string.h header file 3. Declare the following macros (i.e., use #define NOT const) to use as global constants for the application a. ROW with a value of 6 b. COL with a value of 7 c. ONE with a value of 1 d. TWO with a value of 2 e. SPACE with a value of ' ' (NOTE: there is an explicit space between the open and close single quote) f. TRUE with a value of 1 g. FALSE with a value of 0 4. Write the function declaration or prototype for functions a. initializeBoard b. displayBoard c. makeMove 5. Update function playGame to do the following a. Add local variable named board, data type character, two-dimensional array, size 6 rows and 7 columns (i.e., use macros ROW and COL) b. Before the while loop i. Call function initializeBoard; pass as an argument array board c. Inside the while loop i. Comment out or delete call to function displayExplicitBoard ii. Call function displayBoard; pass as an argument array board iii. Inside the if/else if statements 1. Replace the printf statement notifying the player it is their turn with call to function makeMove; pass as arguments a. Character array of players name (i.e., yellow or red)
  • 2. b. 2-d array board 6. Write function initializeBoard to do the following a. Return type void b. Parameter list includes 2-d character array (i.e., board), size 6 rows and 7 columns (i.e., use macros ROW and COL) c. Write a nested for loop to iterate through the rows and columns of array board to do the following i. Set the element at the current row and column in the 2-d array board to an explicit space (i.e., use macro SPACE) 7. Write function displayBoard to do the following a. Return type void b. Parameter list includes 2-d character array (i.e., board), size 6 rows and 7 columns (i.e., use macros ROW and COL) c. Write printf statements to display the top row of the Connect Four board d. Write a nested for loop to iterate through the rows and columns of array board to do the following i. Write a printf statement to display the value stored in the current element of the array board 8. Write function makeMove to do the following d. Return type void e. Parameter list includes i. Character array for the players name (i.e., playerName, size is 20, use macro NAME) ii. 2-d character array (i.e., board), size 6 rows and 7 columns (i.e., use macros ROW and COL) f. Declare variable to store the user input for their move, data type character array, size 2 (i.e., move, use macro TWO) g. Declare variable to store if player move is valid, data type integer, initialize to 0 (i.e., valid, use macro FALSE) h. Loop while the players move input is not valid (i.e., FALSE)
  • 3. i. Write a printf statement to prompt the player to enter their move ii. Write a scanf statement to store the players move in local variable move iii. Write a printf statement to display to the player the move they entered iv. Declare variable to store the length of the players move input, data type integer (i.e., length) set equal to explicit type cast to integer of return value from function call strlen(), pass as an argument variable move v. Evaluate variable length 1. If it is equal to 1, set variable valid equal to true (i.e., use macros ONE and TRUE) 2. If it is not equal to 1, set variable valid equal to false (i.e., use macros ONE and FALSE) vi. Evaluate variable valid, if it is false, write a printf statement to notify the player their move input was not valid (i.e., use macro FALSE) Above are the instructions I need and below is what I currently have. #include #include // global constants a.k.a. macros #define NAME 20 #define YELLOW 1 #define RED 2 #define ZERO 0 #define FOUR 4 // function prototypes void welcomeScreen (); void displayEmptyBoard(); void playGame(); // main function int main()
  • 4. { // call function welcomeScreen welcomeScreen(); // call function displayEmptyBoard // displayEmptyBoard(); // call function playGame playGame(); // program executed successfully return 0; } // welcomeScreen function displays the Connect Four logo and rules of the game void welcomeScreen () { printf (" CCCC OOOO N N N N EEEEE CCCC TTTTT FFFFF OOOO U U RRRR n"); printf ("C O O N N N N N N EE C T F O O U U R R n"); printf ("C O O N N N N N N EEEE C T FFF O O U U R R n"); printf ("C O O N NN N NN EE C T F O O U U R R n"); printf (" CCCC OOOO N N N N EEEEE CCCC T F OOOO UUUU R R n"); printf ("n"); printf ("CONNECT FOUR GAME RULESnn"); printf("t 1. The board is 6 rows and 7 columns.n"); printf("t 2. The player with the yellow discs goes first.n"); printf("t 3. Players drop 1 disc in the grid at a time.n"); printf("t 4. Players alternate turns.n"); printf("t 5. Once a player has four discs in a row vertically, horizontally or diagonally, they have won the game!n"); } // function displayEmptyBoard displays a hardcoded version of an Connect Four board void displayEmptyBoard() { printf("|------------------------------------------n");
  • 5. printf("| A | B | C | D | E | F | G |n"); printf("|------------------------------------------n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); printf("| | | | | | | |n"); printf("|------------------------------------------n"); } void playGame() { // store player names char yellow[NAME]; // Karin char red[NAME]; // Lia // yellow (Y) always goes first int currentPlayer = YELLOW; int loop = ZERO; printf("Player Yellow, please enter your namen"); scanf("%s", yellow); printf("Player Red, please enter your namen"); scanf("%s", red); printf("%s and %s, let's play Connect Four!n", yellow, red); while(loop < FOUR) { // call function displayEmptyBoard displayEmptyBoard(); // switch players for each move if(currentPlayer == YELLOW) {
  • 6. printf("%s, it is your turnn", yellow); // switch players currentPlayer = RED; } else if(currentPlayer == RED) { printf("%s, it is your turnn", red); currentPlayer = YELLOW; } loop++; } } Please provide code screenshots in C language. Thank you