Thread: Need help
View Single Post
Old 10-19-2005, 02:09 AM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
Study this code closely then
Code:
#include <iostream>

int main()
{
  double x=0.0,y=0.0, incr=0.0;
  char move;
  std::cout << "Enter starting Coordinates (X, Y) : ";
  std::cout.flush();
  std::cin >> x >> y;
  std::cin.ignore(); /* discard the '\n' in stdin stream */
  while(move != 'q' && move != 'Q')
    {
      std::cout << "Enter Move : ";
      std::cout.flush();
      std::cin >> move;
      if(move == 'q' || move == 'Q')
	break;/* we gotta go */
      std::cin >> incr;
      std::cin.ignore();
      switch(move)
	{
	case 'n':
	case 'N':
	  /* move north, increase y */
	  break;
	case 'e':
	case 'E':
	  /* move east, increase x */
	  break;
	case 's':
	case 'S':
	  /* move south, decrease y */
	  break;
	case 'w':
	case 'W':
	  /* move west, decrease x */
	  break;
	default:
	  std::cout << "The chosen move (" << move 
		    << ") is unsupported" << std::endl;
	  break;
	}
    }
  std::cout <<"The final position is ("; 
  std::cout << x << ", " ;
  std::cout << y << ")" << std::endl;
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote