I'm currently learning and playing arround with C++ and I wanted to find how come my switch statement only responds to a half of the cases? It only responds when substracting from the integers. Note, that I am as much as a beginner as it is possible to be, so any advice would be really helpful.
#include <fstream>
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define SPACE_BAR 32
void startingCoord (int & x, int & y)
{
cout << "Starting coord" <<endl;
cin >> x >> y;
}
void printGrid(int x, int y)
{
for (int a = 0; a < 10; a++)
{
for (int b = 0; b < 10; b++)
{
if (a + 1 == x && b + 1 == y)
{
cout<<" 0 ";
}
else
{
cout<<" - ";
}
}
cout<<endl;
}
}
int main ()
{
int c = 0, x = 0, y = 0;
startingCoord(x, y);
while (true)
{
printGrid(x, y);
switch (c = getch()){
case SPACE_BAR:
return 0;
case KEY_DOWN:
x++;
case KEY_RIGHT:
y++;
case KEY_UP:
x--;
case KEY_LEFT:
y--;
default:
return 0;
}
cout<<x<<" "<<y;
}
}