C++ if statement on char value

Description

C++ if statement on char value

#include <iostream>
#include <conio.h>              //for getche()

using namespace std;

int main()/*from  www  .j a v a2  s .co  m*/
{
   char dir='a';
   int x=10, y=10;
   cout << "Type Enter to quit\n";
   while( dir != '\r' )         //until Enter is typed
   {
      cout << "\nYour location is " << x << ", " << y;
      cout << "\nPress direction key (n, s, e, w): ";
      dir = getche();           //get character
      if( dir=='n')             //go north
         y--;
      else if( dir=='s' )       //go south
          y++;
      else if( dir=='e' )       //go east
          x++;
      else if( dir=='w' )       //go west
          x--;
   }
   return 0;
}



PreviousNext

Related