Question
Hi! Can you help me fix the error in my code to have the output like this: (my code still have a . next to
Hi! Can you help me fix the error in my code to have the output like this: (my code still have a . next to the C) Thank you!
Which way? R . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
here is my code:
#include
#include
using namespace std;
int x = 0, y = 0;
void drawGameboard(int x, int y)
{
int h = 0, w = 0;
while(h<6)
{
while(w<6)
{
if(h==y && w==x)
{
cout << "C";
}
else
{
cout << ". ";
}
w = w + 1;
}
cout << endl;
h = h + 1;
w = 0;
}
}
void moveUp()
{
if(y <= 0)
{
y = 0;
}
else
{
y = y - 1;
}
}
void moveDown()
{
if (y >= 5)
{
y = 5;
}
else
{
y = y + 1;
}
}
void moveLeft()
{
if (x <= 0)
{
x = 0;
}
else
{
x = x - 1;
}
}
void moveRight()
{
if (x >= 5)
{
x = 5;
}
else
{
x = x + 1;
}
}
int main()
{
char i = 0;
cout << "Welcome Champion" << endl;
cout << "==Valide Moves==" << endl;
cout << "U - Move Up" << endl;
cout << "D - Move Down" << endl;
cout << "L - Move Left" << endl;
cout << "R - Move Right" << endl;
cout << "Q - Quit" << endl;
cout << "===============" << endl;
cout << endl;
while ( i == 0 || i == 'U' || i == 'D' || i == 'L' || i == 'R' || i == 'Q' )
{
if(i == 'U')
moveUp();
else if( i == 'D')
moveDown();
else if( i == 'L')
moveLeft();
else if( i == 'R')
moveRight();
else if( i == 'Q')
return 0;
cout << endl;
drawGameboard(x, y);
cout << "Which way?";
cin >> i;
i = toupper(i);
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started