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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
//Compass project
//Written by Roger Dodd
//Date: 09/21/13
#include <iostream>
//directive, which tells the preprocessor to include the contents of another file.
using namespace std;
int main()
//This is the starting point of the program
{
bool compass = true;
int x = 0;
int y = 0;
// sets up x and y intial values
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";
//cout is an object, defined in the file iostream, that’s used to send data to the standard out put screen
//sends the string of text to the console window
char direction;
//single character variable type
cin >> direction;
//cin is used to get a string, only works with strings that have no whitespace in them
do{
//run loop at least once until conditions are satisfied
if(direction == 'E'||direction == 'e'){
//sets up east direction
x += 1;
//keep count of x direction
cout << "enter direction: N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";
cin >> direction;
}
else if ( x > 0 && y > 0){
cout << "northeast";
cin >> x && y;}
else if ( x < 0 && y < 0){
cout << "southwest";
cin >> x && y;}
else if ( x < 0 && y > 0){
cout << "northwest";
cin >> x && y;}
else if ( x > 0 && y < 0){
cout << "southeast";
cin >> x && y;}
else if ( x = 0 && y != 0){
cout << "y axis";
cin >> x && y;}
else if ( x != 0 && y != 0){
cout << "x axis";
cin >> x && y;}
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);
//prevents infinite loops
return 0;
}
|