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

Develop a C program that receives as input a distance value d in inches and conv

ID: 673623 • Letter: D

Question

Develop a C program that receives as input a distance value d in inches and converts it to yards, feet, and inches (1 yard = 3 feet, 1 foot = 12 inches).

Your program should:

1. Read the distance value d from the keyboard

2. Use a function called dist conv to break distance to yards, feet, and inches.

3. Print the result in the main function (not within the dist conv function)

The dist conv function prototype should be: void dist conv(int d, int *p y, int *p f, int *p i)

Sample run: Enter the distance in inches: 98

98 inches equal 2 yards, 2 feet, and 2 inches.

Explanation / Answer

#include <stdio.h>
void distConv(int d, int *py, int *pf, int *pi)/*Function to convert the distance in inches, to yards, feet, and inches*/
{
*pi = d % 12;   /*the distance when divided by 12, the remainder will be the inches leftover.*/
*pf = d / 12;   /*With the same operation above, the quotient will be the feet. (Only feet not yards.)*/
*py = *pf / 3;/*Now when the feet is divided by 3, the quotient will be the yards.*/
*pf = *pf % 3;/*The left over(remainder) in the above operation will be the feet.*/
}

int main()
{
int d, py, pf, pi;
printf("Enter the distance in inches: ");       /*Read inches as input.*/
scanf("%i", & d);
distConv(d,&py,&pf, &pi);                       /*Convert into yards, feet, and inches.*/
printf("%i inches equal %i yards, %i feet, and %i inches. ", d, py, pf, pi);/*Print the result in yards, feet, inches.*/
}