Question: Vending Machine Project on C programming Is there any way to make it shorter? It works as I need it to be BUT I dont

Vending Machine Project on C programming

Is there any way to make it shorter? It works as I need it to be BUT I dont know why i have to enter the coin letter (N/D/Q) twice in order to work out. Can anybody help me?

so far I have this:

#include #include

int main() { char coin; int price=65; int input=0; int change=0;

{ printf("Enter 65 cents for a drink > "); scanf("%c", &coin); while(coin!='R') { scanf("%c", &coin); if(coin=='C') { if(input<65) { change=price-input; printf("Sorry, insufficient funds entered "); printf("Please enter additional %d cents > ", change); scanf("%c", &coin); } else { change=input-price; printf("Cola drink dispensed"); printf(" %d cents in change given", change); exit(0); } } else if(coin=='O') { if(input<65) { change=price-input; printf("Sorry, insufficient funds entered"); printf("Please enter additional %d cents > ", change); scanf("%c", &coin); } else { change=input-price; printf("Orange drink dispensed"); printf(" %d cents in change given", change); exit(0); } } else if(coin=='L') { if(input<65) { change=price-input; printf("Sorry, insufficient funds entered"); printf("Please enter additional %d cents > ", change); scanf("%c", &coin); } else { change=input-price; printf("Lemon drink dispensed"); printf(" %d cents in change given", change); exit(0);

} } else if(coin=='S') { if(input<65) { change=price-input; printf("Sorry, insufficient funds entered"); printf("Please enter additional %d cents > ", change); scanf("%c", &coin); } else { change=input-price; printf("Spritzer drink dispensed"); printf(" $d cents in change given", change); exit(0); } } else if(coin=='Q') { input+=25; printf(" %d cents received > ", input); } else if(coin=='N') { input+=5; printf(" %d cents received > ", input); } else if(coin=='D') { input+=10; printf(" %d cents received > ", input); } coin=' '; if(input>=65) { printf(" Make your drink selection now > "); scanf("%c", &coin); } else scanf("%c", &coin); if(coin=='R') { printf("%d cents returned", input); printf(" "); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!