Compass project

Pages: 12
Use the code JLBorges provided add
while(direction != 'q' && direction != 'Q')
and take care where you put
char direction;in the code
it works fine :)
Chriscpp wrote:
while(direction != 'q' && direction != 'Q')


IMO, don't do that - it is messy, ugly, error prone & not scalable.

@Radkowboy

Use a bool controlled while loop, like what I had in my link.

Also, please always use code tags. Edit your post, select all the code, press the <> button on the right under the format menu.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

@TheIdeasMan

Thank you for the code tag advice. I will do that from now on.

I would like to try your suggestion for my program but it is too complicated for me to apply the suggestion to my program. I know very little about C++ because I am trying to learn it in an online class with basically only a book to help me. I have zero programing experience. I should be paying you guys to learn it because at least your helpful.
> it is too complicated for me to apply the suggestion to my program.

You are not going to learn programming unless you try to write some code.

First, make sure that you have understood everything in the program so far. Then try to write a loop.

You will probably make mistakes; and you may not be able to correct some of them on your own. Try to compile your code; and if there are errors that you can't fix, post the code here along with the error messages and someone will help you out.

Once you are able to compile the code without errors, run it to see if its is working. Again, if there are errors that you can't fix, post the code here along with a brief description of what is not working.
Thank you everyone for your help. I was able to get the program to enter the right coordinates and now I am trying to get it to output the quadrant they are in. The below code is what I am trying do. It worked when I used one else if for northeast but when I put the rest in it no longer puts in the quadrant. Doe anyone have any advice for me?

Thank you

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//Compass project
//Written by Roger Dodd
//Date: 09/21/13

#include <iostream>
//directive, which tells the preprocessor to include the contents of another file.

using namespace std;



int main()
    //This is the starting point of the program

{
    bool compass = true;


    int x = 0;
    int y = 0;
    // sets up x and y intial values
    cout << "enter direction:  N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";   
    //cout is an object, defined in the file iostream, that’s used to send data to the standard out put screen
    //sends the string of text to the console window
   
    char direction;
    //single character variable type
    cin >> direction;
    //cin is used to get a string, only works with strings that have no whitespace in them

   
    do{
        //run loop at least once until conditions are satisfied
    if(direction == 'E'||direction == 'e'){
        //sets up east direction
        x += 1;
        //keep count of x direction
        cout << "enter direction:  N (north), E (east), S (south), W (west) or Q to pause: (" << x << "," << y << ")";   
        cin >> direction;
		
    }

	else if ( x > 0 && y > 0){
		cout << "northeast";
		cin >> x && y;}

	else if ( x < 0 && y < 0){
		cout << "southwest";
		cin >> x && y;}

	else if ( x < 0 && y > 0){
		cout << "northwest";
		cin >> x && y;}

	else if ( x > 0 && y < 0){
		cout << "southeast";
		cin >> x && y;}

	
	else if ( x = 0 && y != 0){
		cout << "y axis";
		cin >> x && y;}

	else if ( x != 0 && y != 0){
		cout << "x axis";
		cin >> x && y;}

    else if(direction == 'S'||direction == 's'){
        y -= 1;
        cout << "enter direction:  N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";   
        cin >> direction;
    }

    else if(direction == 'N'||direction == 'n'){
        y += 1;
        cout << "enter direction:  N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";   
        cin >> direction;
    }

    else if(direction == 'W'||direction == 'w'){
        x -= 1;
        cout << "enter direction:  N (north), E (east), S (south), W (west) or Q to pause:(" << x << "," << y << ")";   
        cin >> direction;
    }
   
    else if (direction == 'q' || direction == 'Q')
    system ("pause");
   
        }while(compass == true);
    //prevents infinite loops
   
   
       

    return 0;
}
Topic archived. No new replies allowed.
Pages: 12