Skip to content

Instantly share code, notes, and snippets.

@eogas
Forked from kdmkdmkdm/revisedAgainC++
Created April 22, 2012 19:19
Show Gist options
  • Save eogas/2466287 to your computer and use it in GitHub Desktop.
Save eogas/2466287 to your computer and use it in GitHub Desktop.
revisedAgainC++
// 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