dimanche 25 novembre 2018

Switch statment exercise

I have this exercise i am trying to solve but i get stuck , when i compile it after the first printf function ("please select a drink ) it stops . it just let'S choose a drink and thats about it and i cant seem to find the problem , thanks

Imagine, you develop software for a vending machine, with the following functionality:

• 3 drinks, namely water, bionade and orange juice should be offered.

• The drinks are to be selected with the respective first letter. Either Uppercase and lowercase letters are allowed.

• Water costs 0.5 $, Bionade 1 $ and orange juice 2 $.

• You can only pay with one (matching) coin.

• In case of invalid selection or invalid insertion, the program should have a Output error message and schedule.

#include <stdio.h>
int main() {
int a;
char W,O,B;
printf("please select a drink : ");
scanf("%d",&a);
switch(a)
{
case 'W':
  printf("please put %f dollars in: \n",W = 0.5);
  break;
case 'O':
  printf("please put %f dollars in:", O = 1);
  break;
case 'B':
  printf("please put %f dollars in:",B = 2);
  break;
default :
    printf("please take your drink");
    break;  
}
 return(0);
}

Aucun commentaire:

Enregistrer un commentaire