0
Im new at programming and don't understand whats wrong in my code.. I would like some help to solve it
Switch case statement https://code.sololearn.com/ctYrIfE9yMqx/?ref=app
5 odpowiedzi
+ 1
Kakuzu,
Since you are taking <bloodtype> as `char`, your switch cases should evaluate `char` rather than `int` literals.
You can choose to use getchar() or scanf() to read value of <bloodtype>
char bloodtype = getchar();
scanf( "%c ", &bloodtype );
And your switch cases should evaluate `char`. Remember `char` is single-quoted ...
case '1':
// your code here
break;
case '2':
// your code here
break;
// etc. etc ...
+ 3
Try now sorry i haven't seen your switch cases
#define typeA 3000.00
#define typeB 1800.00
#define typeC 2880.00
#define typeO 1500.00
int main() {
int bloodtype;
float volume;
bloodtype = scanf("%d",&bloodtype);
scanf("%f", &volume);
switch(bloodtype){
case 1:printf("%.2f", volume * typeA);
break;
case 2:printf("%.2f", volume * typeB);
break;
case 3:printf("%.2f", volume * typeC);
break;
case 4:printf("%.2f", volume * typeO);
break;
}
return 0;
}
+ 2
♨️A.S.♨️
You forgot the library in the beginning of the code.
#include <stdio.h>
+ 1
Thanks man Ipang.. And for those who helped me i appreciate it and helped me fixed the code
0
It still wont display the value