1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
using namespace std;
int main()
{
bool compass = true;
int x = 0;
int y = 0;
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";
char direction;
cin >> direction;
do{
if(direction == 'E'||direction == 'e'){
x += 1;
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";
cin >> direction;
}
else if(direction == 'S'||direction == 's'){
y -= 1;
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";
cin >> direction;
}
else if(direction == 'N'||direction == 'n'){
y += 1;
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";
cin >> direction;
}
else if(direction == 'W'||direction == 'w'){
x -= 1;
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";
cin >> direction;
}
else if (direction == 'q' || direction == 'Q')
system ("pause");
}while(compass == true);
return 0;
}
|