I need a program with the info below and EXPLAIN waht each line of code means? T
ID: 3548597 • Letter: I
Question
I need a program with the info below and EXPLAIN waht each line of code means? This is basic C programming not C++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 I need a program with the info below and EXPLAIN waht each line of code means? This is basic C programming not C++
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, int *, int *, int *, int *);
int main()
{
int initialAmt;
int cups = 0;
int gallons = 0;
int quarts = 0;
int pints = 0;
printf("Enter the number of cups: ");
scanf("%d", &initialAmt);
liquid(initialAmt, &gallons, &quarts, &pints, &cups);
printf("%d cups: %d gallons, %d quarts, %d pints, %d cups ", initialAmt, cups, gallons, quarts, pints);
return 0;
}//end main
void liquid(int intAmt, int *gallons, int *quarts, int *pints, int *cups)
{
*gallons = intAmt/16;
intAmt = intAmt % 16;
*quarts = intAmt / 4;
intAmt = intAmt % 4;
*pints = intAmt / 2;
intAmt = intAmt % 2;
*cups = intAmt;
}//end liquid
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.