switch help

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
#include <iostream>

using namespace std;

char moveto;

void playgamez()
{
    cout<<"You are now standing on z. Were do you want to move?\n";
    cout<<"[q][w][e]\n[a][s][d]\n[0][x][c]\n";
    cin>> moveto;
    cin.get();
}







int main()
{
    char moveto;
    int array[3][3];

    cout<<"You are standing on 4. Were do you want to move?\n";
    cout<<"[q][w][e]\n[a][0][d]\n[z][x][c]\n";
    cin>> moveto;
    cin.get();

    switch ( moveto ) {
        case z:
         playgamez();
         break;
        case x:
         x();
         break;
        case c:
         c();
         break;
        case a:
         a();
         break;
        case s:
         s();
         break;
        case d:
         d();
         break;
        case q:
         q();
         break;
        case w:
         w();
         break;
        case e:
         e();
         break;

    }
}


When i try to compile this i get this error: error: 'z' was not declared in this scope. I get this error on line 32,35,38,41,44,47,50,53,56. Can anyone tell me what I have to change to get it to work?
when you just write z it thinks you mean a variable or something. If you want the char value z you have to put single quotes around 'z'.

All these functions x(), c(), etc. don't exist in your code so you will have to create them to be able to call them.
Last edited on
ty :) , but I did what you said and now it say that i can't build it, (I'm using codeblocks)
Last edited on
That that @Peter87 said is what you have wrong.

Also why do you use
1
2
    cin>> moveto;
    cin.get();

inside your playgamez()? There is no effect for that here and I am not sure you really need cin.get(); anyway. You also use it on line 29. This is used as a portable alternative to stop the console from closing after program termination. No point using it here.

You have also declare char moveto twice and although it will compile I guess you didn't intend to use a global (line 5) and a local (line 23 inside main()) version.
Topic archived. No new replies allowed.