Error messages

I have two error messages in the code below that I have no idea what they mean. Knot knowing what they mean means that I am unable to fix them.

The errors are

error: switch quantity not an integer
error case label does not reduce to an integer constant


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
  #include <stdio.h>

 int main(int argc, char *argv[])
 {
 float inputamount, result;

 printf("\n\n Enter amount to be converted"); 
 printf("\n in the form  SA, where the");
 printf("\n where the two letters represent");
 printf("\n a country.");
 printf("\n ad = Australian dollars.");
 printf("\n gb = British Pounds.");
 printf("\n jp = Japenes yen.");
 printf("\n vd= Vitnames dollars.");
 printf("\n\n Enter amount to convert: ");

 switch(inputamount)
 {
 
case "ad":
 result = inputamount * 1.044;
break;

 case "gb":
 result = inputamount / 0.63;
 break;

 case "jp":
 result = inputamount * 95.057;

 case "vd":
 result = inputamount * 2.106;

break;

default:
The messages mean what they say.

Here switch(inputamount) should be an integer, but it is declared as float inputamount.

In the case statement such as case "ad":, the value "ad" isn't an integer and can't be converted to an integer.

In any case, even if the compiler accepted this code, it would mean a variable of type float was being compared with a string of characters, which doesn't make much sense. So really the compiler is helping you by pointing out that what you are asking it to do doesn't make sense.

Last edited on
Topic archived. No new replies allowed.