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

18th Nov 2021, 11:04 AM
Christian Jay Medallo
Christian Jay Medallo - avatar
5 Réponses
+ 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 ...
18th Nov 2021, 12:26 PM
Ipang
+ 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; }
18th Nov 2021, 11:34 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
♨️A.S.♨️ You forgot the library in the beginning of the code. #include <stdio.h>
18th Nov 2021, 4:24 PM
SoloProg
SoloProg - avatar
+ 1
Thanks man Ipang.. And for those who helped me i appreciate it and helped me fixed the code
19th Nov 2021, 3:57 AM
Christian Jay Medallo
Christian Jay Medallo - avatar
0
It still wont display the value
18th Nov 2021, 11:25 AM
Christian Jay Medallo
Christian Jay Medallo - avatar