Answer to Question #328386 in C++ for nickname

Question #328386

This program will draw a playing field where the user decides the location of the Hero.

Enter the row # of the hero:   [user types: 1]

Enter the column # of the hero:  [user types: 3]


--H---------

-------------

-------------

-------------

-------------


1
Expert's answer
2022-04-13T13:18:15-0400
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void main()
{
	const int N = 5, M = 8;
	vector<vector<string> >vec(N, vector < string>(M));
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			vec[i][j] = "--";
		}
	}
	int row, column;
	char ch;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cout << vec[i][j];
		}
		cout << endl;
	}
	do
	{
		cout << "\nEnter the row # of the hero: ";
		cin >> row;
		cout << "\nEnter the column # of the hero: ";
		cin >> column;
		vec[row-1][column-1] = "H";
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < M; j++)
			{
				cout << vec[i][j];
			}
			cout << endl;
		}
		cout << "\nDo you want to continue? [Y/N]: ";
		cin >> ch;
		vec[row-1][column-1] = "--";
	} while (ch == 'Y');
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS