I keep getting errors. Programming in C Program 4. Write a program that combines
ID: 3753011 • Letter: I
Question
I keep getting errors. Programming in CProgram 4. Write a program that combines programs 1 through 3 into one vending machine user interface program. First welcome the user and display the drink options, prompt the user for their drink selection, enter their selection, and record the amount due for a small (program 3). Next, display the size options, prompt the user for the size, enter their size selection, and record the price multiplier (program 2). Based on the size entered, your program should adjust the amount due. Next, display the amount due, prompt the user for their payment, enter their payment, and determine the amount of change to return (program 1). Note: the flow chart for this program does not have to include the entire flow charts for programs 1 through 3. Rather, it can put a brief description of each of the smaller programs in a compute box and show the flow of control for between each smaller program. Any additional computations or control should also be included In program 4 you should remove any unnecessary print statements used in programs 1 through 3 that do not display useful information to the user.
Explanation / Answer
#include<stdio.h>
int main()
{//variable declaration
int price_multiplier=0;//to store price multiplier value
int price;//price variable
printf("--------------WELCOME------------ ");
printf("Drinks available are: 1:Pepsi price:$10 2:Mirinda price:$20 3:Coke price:$30 Enter option:");
int p;
scanf("%d",&p);
if(p==1)
{
price=10;
printf("Pepsi selected, price is :$%d ",price);
}
else if(p==2)
{
price=20;
printf("Mirinda selected, price is :$%d ",price);
}
else
{
price=30;
printf("Coke selected, price is :$%d ",price);
}
char c;
scanf("%c",&c);
//prompting input
printf(" Sizes Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small, Enter:");
//reading input//reading char
scanf("%c",&c);
if(c=='s'||c=='S')//means small
{
//updating price multiplier
price_multiplier=1;//increases cost by 1 time
//printing message
printf("You have orderded a Small drink ");
}
else if(c=='m'||c=='M'){
//updating price multiplier
price_multiplier=2;//increases cost by 2 times
//printing message
printf("You have orderded a Medium drink ");
}
else if(c=='l'||c=='L')
{
//updating price multiplier
price_multiplier=3;////increases cost by 3 timess
//printing message
printf("You have orderded a Large drink ");
}
else
{
printf("Error : Invalid drink size ");//printing error message
}
//printing price multiplier
printf("Amount is:$%d ",price_multiplier*price);
int d = price_multiplier*price;
if(d!=0)
{
printf("Enter payment:");//taking payment
int pp;
scanf("%d",&pp);
pp=pp-d;
if(pp==0)//
printf("Thank you ");
else if(pp>0)
{
printf("Change to be returned:%d ",pp);
printf("Thank you ");
}
else
{
printf("Additional money to be paid:%d ",pp*-1);
}
}
return 0;
}
output:
--------------WELCOME------------
Drinks available are:
1:Pepsi price:$10
2:Mirinda price:$20
3:Coke price:$30
Enter option:1
Pepsi selected, price is :$10
Sizes
Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small,
Enter:m
You have orderded a Medium drink
Amount is:$20
Enter payment:30
Change to be returned:10
Thank you
Process exited normally.
Press any key to continue . . .