C Project 4. Write a program jar.c. Use an enumerated variable ‘jar_type’ to ind
ID: 3788857 • Letter: C
Question
C Project
4. Write a program jar.c. Use an enumerated variable ‘jar_type’ to indicate the types of jar available in the store.
Jar Type
Amount of liquid in ml
Cup
236.588
Pint
473.176
Quart
946.353
Half Gallon
1892.705
Full Gallon
3785.41
Use the ‘scanf’ statement to get the jar type and the # of jars to be purchased from the user.
Convert the amount of liquid that the purchased jars could hold to milliliters and display it on the terminal using the above table. Use a switch case construct. Make sure that the output display follow the same format of the sample output given below.
Sample Output:
Enter the type of jar to be purchased as a number (I. e) 1-cup, 2-Pint, 3-Quart, 4-Half Gallon, 5- Gallon: 1
Enter the number of jars to be purchased: 4
Total amount of liquid in ml: 946.352
Jar Type
Amount of liquid in ml
Cup
236.588
Pint
473.176
Quart
946.353
Half Gallon
1892.705
Full Gallon
3785.41
Explanation / Answer
#include<stdio.h>
enum jar_type{
Cup=236,
Pint=473,
Quart=946,
HalfGallon=1892,
FullGallon=3785
};
int main()
{
enum jar_type ex;
int ch,num;
printf(" Enter the type of jar to be purchased as a number (I. e) 1-cup, 2-Pint, 3-Quart, 4-Half Gallon, 5- Gallon: ");
scanf("%d",&ch);
printf(" Enter the number of jars to be purchased: ");
scanf("%d",&num);
switch(ch){
case 1:
ex=Cup;
printf(" Total amount of liquid in ml:%lf",(float)(num)*(ex+0.588));
break;
case 2:
ex=Pint;
printf(" Total amount of liquid in ml:%lf",(float)(num)*(ex+0.176));break;
case 3:
ex=Quart;
printf(" Total amount of liquid in ml:%lf",(float)(num)*(ex+0.353));break;
case 4:
ex=HalfGallon;
printf(" Total amount of liquid in ml:%lf",(float)(num)*(ex+0.705));break;
case 5:
ex=FullGallon;
printf(" Total amount of liquid in ml:%lf",(float)(num)*(ex+0.41));break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.