Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

Students also viewed these Databases questions

Question

1. Have you ever taken any digital marketing courses?

Answered: 1 week ago