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

Programming in C Writing C Program(s) Using Variables, Declaration Statements &

ID: 3678700 • Letter: P

Question

Programming in C Writing C Program(s) Using Variables, Declaration Statements & Basic C Data Types Complete and submit Programming Exercise #8 listed on Page 97 of your textbook. This is the info from the textbook:

In the U.S. system of volume measurements, a pints is 2 cups , a cup is 8 ounces, an ounce is 2 tablespoons and a tablespoon is 3 teaspoons. write a program that requests a volume in cups and displays the equivalent volumes in pints, ounces, tablespoons, and teaspoons. Why does a floating-point type make more sense for this application than an integer type?

Explanation / Answer

#include<stdio.h>

int main(){
   float cups;
  
   printf("Enter volume in cups: ");
   scanf("%f", &cups);
  
   printf("Volume in pints is: %.3f ",(cups/2.0));
  
   printf("Volume in ounces is: %.3f ",(cups/8.0));
  
   printf("Volume in tablespoons is: %.3f ",(cups/16.0));
  
   printf("Volume in teaspoons is: %.3f ",((cups/16.0)*3));
  
   return 0;
   }

Since, an Integer volume can not fit completely in all types of jars, there may be chance that a integer volume can fit only some fraction in other jars, so we need floating point type.
/*

Output:

Enter volume in cups: 12
Volume in pints is: 6.000
Volume in ounces is: 1.500
Volume in tablespoons is: 0.750
Volume in teaspoons is: 2.250

*/