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---------
-------------
-------------
-------------
-------------
#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');
}
Comments
Leave a comment