Alex Sturza Alex Sturza - 1 year ago 97
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':



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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download