Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with getting started. Programming in C change they will receive. Next

ID: 3752846 • Letter: N

Question

Need help with getting started. Programming in C
change they will receive. Next print a message (such as "Thank you -enjoy your drink") and end t program normally (at the return O statement). Note, your program should be able to handle all amounts of money (not just multiples of dollars but also cents such as $1.25). Also you may assume that the user is only entering a number and not the (though the $could be part of your prompt). Hint: Check how to do floating point comparisons! Program 2. Write a program to determine the drink size based on the letter the user enters. Print a message to the user giving the various drink size options and then prompt the user for the drink size. The user can enter an 's' or 'S' for small, an 'm' or 'M' for medium, and an '' or 'L' for large. Depending on which size the user requests, print a message such as: "You have ordered a (small, medium, large) drink." In addition to displaying the size ordered, also record a price multiplier. The price multiplier for a small is 1, for a medium is 2, and for a large is 3. If the user does not enter a valid character, print an error message (such as "Error: Invalid drink size") and exit the program. 2 You should use nested if-then-else statements for this problem. After the nested if-then-else statements, print the value of the price multiplier to ensure that the correct value was recorded (the price multiplier will be used in program 4). Hint: use the logical OR expression in your comparisons. Program 3. Write a program that displays the various drinks your vending machine offers along with the option number for each drink Beside each option include the price (you can set the cost for the small, the costs for medium should be 2 times the cost of the small and the cost of the large should be 3 times the cost of the small). 9 2

Explanation / Answer

//program 2

#include<stdio.h>

int main()

{//variable declaration

int price_multiplier=0;//to store price multiplier value

char c;

//prompting input

printf("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;

//printing message

printf("You have orderded a Small drink ");

}

else if(c=='s'||c=='S'){

//updating price multiplier

price_multiplier=2;

//printing message

printf("You have orderded a Medium drink ");

}

else if(c=='l'||c=='L')

{

//updating price multiplier

price_multiplier=3;

//printing message

printf("You have orderded a Large drink ");

}

else

{

printf("Error : Invalid drink size ");//printing error message

}

//printing price multiplier

printf("Price multiplier is:%d ",price_multiplier);

return 0;

}

outpu1t:

Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small,

Enter:s

You have orderded a Small drink

Price multiplier is:1

Process exited normally.

Press any key to continue . . .

output2:

Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small,

Enter:l

You have orderded a Large drink

Price multiplier is:3

Process exited normally.

Press any key to continue . . .

output3:

Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small,

Enter:h

Error : Invalid drink size

Price multiplier is:0

Process exited normally.

Press any key to continue . . .

//program 3

#include<stdio.h>

int main()

{//variable declaration

int price_multiplier=0;//to store price multiplier value

int price=10;//price variable

char c;

//prompting input

printf("Vending Machine-- Price of drink :$10 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=='s'||c=='S'){

//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("Price of the drink is:$%d ",price_multiplier*price);

return 0;

}

output:

Vending Machine--

Price of drink :$10

Sizes

Enter an 's' or 'S' for Small,an 'm' or 'M' for Medium, an 'l' or 'L' for Small,

Enter:l

You have orderded a Large drink

Price of the drink is:$30

Process exited normally.

Press any key to continue . . .

//if any problem in understanding ,, pls feel free to ask