Write a C program can display a grid and take input from user. Start program by:
ID: 3868382 • Letter: W
Question
Write a C program can display a grid and take input from user.
Start program by: game playera playerb height width. (Board size 1-1000)
Player A will go first, ask user input coordinates(e.g PlayerA: 0 0)
0 wins by connecting left to right edges while X wins by connecting top and bottom edges
When winner is determined, display player? wins
Display error messages:
When user input incorrect player type message: invalid type
When grid dimmesion is invlaid message: invalid grid
E.g. this is a 4x4 grid Player A: 00 0 Player :1.1 0 Player A wins: .X X. Player B wins ·X0. ·X0.Explanation / Answer
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
char **createboard(int rows, int cols)
{
char** boardArray = new char*[rows];
for (int i = 0; i < rows; ++i) {
boardArray[i] = new char[cols];
}
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
boardArray[i][j] = char(i + 65);
}
}
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cout << boardArray[i][j];
}
cout << endl;
}
for (int i = 0; i < rows; ++i) {
delete[] boardArray[i];
}
delete[] boardArray;
return boardArray;
}
int main()
{
int rows = 0;
int cols = 0;
char **boardArray = createboard(rows, cols);
cout << " Welcome to Tic Tac Toe v1! " << endl;
cout << " Choose your board width: " << endl;
cin >> rows;
cout << " Choose your board height " << endl;
cin >> cols;
cout << endl;
createboard(rows, cols);
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.