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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started