-
-
Save eogas/2466287 to your computer and use it in GitHub Desktop.
revisedAgainC++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// navigatorProgram: My first semi-good C++ program. | |
#include "stdafx.h" | |
#include <iostream> | |
#include <cctype> | |
using namespace std; | |
int main() | |
{ | |
// Declare. | |
int positionX = 0; | |
int positionY = 0; | |
char go = 'a'; | |
bool q = false; | |
while (!q) | |
{ | |
// Show current position. | |
cout << "Current Position = (" << positionX << ", " << positionY << ")" << endl; | |
// Figure out where user wants to go. | |
cout << "Move (N)orth, (E)ast, (S)outh, (W)est or (Q)uit?" << endl; | |
cin >> go; | |
switch( toupper(go) ) | |
{ | |
case 'N': | |
++positionY; | |
break; | |
case 'E': | |
++positionX; | |
break; | |
case 'S': | |
--positionY; | |
break; | |
case 'W': | |
--positionX; | |
break; | |
case 'Q': | |
cout << "Exiting..." << endl; | |
q = true; | |
break; | |
default: | |
cout << "You have entered an invalid direction." << endl; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment