Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created April 22, 2012 16:54
Show Gist options
  • Save kdmkdmkdm/2465275 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/2465275 to your computer and use it in GitHub Desktop.
revisedAgainC++
// navigatorProgram: My first semi-good C++ program.
#include "stdafx.h"
#include <iostream>
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( go )
{
case 'N':
case 'n':
++positionY;
break;
case 'E':
case 'e':
++positionX;
break;
case 'S':
case 's':
--positionY;
break;
case 'W':
case 'w':
--positionX;
break;
case 'Q':
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