Very simple Navigation program

I'm trying to write a program for practice. This program is supposed to collect input data (n, s, e, w for north, south, east, and west) and then display the co-ordinates like this: (0,0). Then when you press n, for example, it will display (0,1) and then save that data. Then press, say e for east and display (1,1). This is my code. But no matter what input character I type, it only displays (0,1) and then exits! What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stdafx.h"
#include <iostream>
#include <String>
using namespace std;



int main()


{


	int m1 = 0;
	int m2 = 0;

	cout << "(" << m1 << "," << m2 << ")" << endl;	
		
	char inputChar;
	cin >> inputChar;

	
	
	if(inputChar == 'e'){
		m1 += 1;
		cout << "(" << m1 << "," << m2 << ")" << endl;	
	}
		

	return 0;
}

I figured it out, actually. I was telling the compiler to end the line before it even got to the switch statement. If anyone is interested, here is my revised code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdafx.h"
#include <iostream>
#include <String>
using namespace std;



int main()


{
	bool play = true;

	int m1 = 0;
	int m2 = 0;

	cout << "(" << m1 << "," << m2 << ")";	
		
	char inputChar;
	cin >> inputChar;

	
	do{
	if(inputChar == 'e'){
		m1 += 1;
		cout << "(" << m1 << "," << m2 << ")";	
		cin >> inputChar;
	}

	else if(inputChar == 's'){
		m2 -= 1;
		cout << "(" << m1 << "," << m2 << ")";	
		cin >> inputChar;
	}

	else if(inputChar == 'n'){
		m2 += 1;
		cout << "(" << m1 << "," << m2 << ")";	
		cin >> inputChar;
	}

	else if(inputChar == 'w'){
		m1 -= 1;
		cout << "(" << m1 << "," << m2 << ")";	
		cin >> inputChar;
	}
	}while(play == true);
		

	return 0;
}
Topic archived. No new replies allowed.