Alex Sturza Alex Sturza - 29 days ago 15
C Question

why my case give me the errors?Why i can't put variables in switch cases?

I have 2 errors while trying to put a variable in switch case:

#include <stdio.h>
int main(int argc, char *argv[]) {
float conversie = 0;
float leu = 1;
float usd = 3.6 * leu;
float eur = 4.4 * leu;
float aur = 139 * leu;
float suma;
float valoare;
char tipmoneda;
printf("introdu moneda pe care vrei sa o schimbi:");
scanf("%c\n", &tipmoneda);
switch (tipmoneda) {
case 'usd':

default:
break;
}

}


These are the errors:

Untitled.c:14:8: warning: multi-character character constant [-Wmultichar] case 'usd': ^
Untitled.c:14:8: warning: overflow converting case value to switch condition type (7697252 to 100) [-Wswitch]
2 warnings generated.

Answer

C switch case only works with integer or single character types.