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

2. Write a C function named liquid() that is to accept an integer number and the

ID: 3677454 • Letter: 2

Question

2. Write a C function named liquid() that is to accept an integer number and the addresses of the variables gallons, quarts, pints, and cups. The passed integer represents the total number of cups, and the function is to determine the number of gallons, quarts, pints, and cups in the passed value. Using the passed addresses, the function should directly alter the respective variables in the calling function. Use the relationships of 2 cups to a pint, 4 cups to a quart, and 16 cups to a gallon. Include this function in a program, printing the results after the function has run. If the user enters 27 cups, the output should be: 1 gallon 2 quarts 1 pint 1 cup and not: 1 gallon 6 quarts 13 pints 27 cups

Explanation / Answer

#include<stdio.h>

void liquid(int number, int *gallons, int *quarts, int *pints, int *cups){
   // getting number of gallon
   *gallons = number/16;
   number = number%16;
  
   // getting number of quart
   *quarts = number/4;
   number = number%4;
  
   //getting number of pint
   *pints = number/2;
   number = number%2;
  
   // number of cup
   *cups = number;
   }
int main(){
  
   int gallons = 0, pints = 0, quarts = 0, cups = 0;
   int number;
  
   printf("Enter number of cups: ");
   scanf("%d",&number);
  
   liquid(number, &gallons, &quarts, &pints, &cups);
  
   printf("%d gallon %d quart %d pint %d cup ",gallons,quarts, pints,cups);
   return 0;
   }


/*

Output:

Enter number of cups: 27
1 gallon 2 quart 1 pint 1 cup

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote