Help me fix

It shows error when I try to compile it
please help

#include <stdio.h>

const char"a, b, c, d, q"
int main()
{
char char1;
const char ("a, b, c, d, q"
printf("Select and type a character from (a, b, c, d, q), then <ENTER>\n");
printf("q for normal quit\n");
scanf("%c", char1);
a=1;
b=2;
c=3;
d=4;
q=5;
switch (number);
{
case 1:
printf("\n Wanted character <a> typed");
break;
case 2:
printf("\n Wanted character <b> typed");
break;
case 3:
printf("\n Wanted character <c> typed");
break;
case 4:
printf("\n Wanted character <d> typed");
break;
case 5:
printf("\n Normal QUIT. Bye.");
break;
default:
printf("\n Unwanted character <char1> typed")
}

return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

int main()
{
    puts( "type a character from (a, b, c, d, q), then <ENTER>\nq for normal quit" ) ;
    char input ;
    scanf( "%c", &input ) ; // pass the address to scanf

    switch(input)
    {
        case 'a' : case 'b' : case 'c' : case 'd' :
            printf( "wanted character '%c' typed\n", input ) ;
            break ; // do not fall through to the next case. we are done.

        case 'q' :
            puts( "'q' : normal quit" ) ;
            break ; // do not fall through to the next case. we are done.

        default:
            printf( "*** error ***
                    unwanted character '%c' typed\n", input ) ;
    }
}
thanks a lot
so i didnt have to declare the a, b, c, d, q?
Assuming that this is C: a case label can't be a variable.

'a', 'b' etc. are character literals (C calls them 'character constants'); we don't have to declare them.

1
2
3
4
5
6
7
const char a = 'a' ; /* a is variable of type const char */

switch(input)
{
     case a : /* variable: error in C, fine in C++ */
     case 'b' : /* fine in both C and C++ */
}
Topic archived. No new replies allowed.