Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programming question: The below code creates a grid based on user input, I need to spawn two characters ( one in the upper right

C++ programming question: The below code creates a grid based on user input, I need to spawn two characters ( one in the upper right hand corner and one in the lower left hand corner denoted with a * on the grid). Every second the characters will move one random direction ( north, south, east or west). Once they end up on the same array position the problem will end displaying how many moves it took. I am having trouble figuring out what to do next. Please help if you can.

#include

int main()

{

unsigned int rows = 0, cols = 0;

std::cout << "Enter 2 <= Rows <=50: ";

std::cin >> rows;

std::cout << "Enter 2 <= Columns <=50: ";

std::cin >> cols;

while (! (rows >=2 && rows <= 50 && cols >=2 && cols <= 50 && rows != cols))

{

std::cout << "Invalid Input ";

std::cout << "Enter 2 <= Rows <=50: ";

std::cin >> rows;

std::cout << "Enter 2 <= Columns <=50: ";

std::cin >> cols;

}

int arrayxy [rows][cols];

for (int i = 0; i < rows; ++i)

{

for(int j = 0; j < cols; ++j)

{

arrayxy[i][j] = 0;

std::cout << arrayxy[i][j];

}

std::cout << ' ';

}

return 0;

}

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions