Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created April 22, 2012 03:30
Show Gist options
  • Save kdmkdmkdm/2446820 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/2446820 to your computer and use it in GitHub Desktop.
navigatorProgramCPlusPlus
// 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;
if(go == 'N' || go == 'n')
{
++positionY;
}
else if(go == 'E' || go == 'e')
{
++positionX;
}
else if(go == 'S' || go == 's')
{
--positionY;
}
else if(go == 'W' || go == 'w')
{
--positionX;
}
else if(go == 'Q' || go == 'q')
{
cout << "Exiting..." << endl;
q = true;
}
else
{
cout << "You have entered an invalid direction." << endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment