Question

Write a program that contains the function measure() that is to accept a long integer number...

Write a program that contains the function measure() that is to accept a long integer number total and the addresses of the integer variables inches, feet, yards, and miles. The passed long integer represents the total number of inches, and the function is to determine the number of miles, yards, feet, and inches in the passed value, writing these values directly into the respective variables declared in the calling function.

This function will be called from the main program and when it returns to main, it will print out the values of inches, feet, yards, and miles.

Use the relationships:

inch

foot (12 inches)

yard (36 inches; 3 feet)

mile (5280 feet; 1760 yards; 63,360 inches)

I have posted the C program I've written so far and just can't seem to get the correct output.

#include <stdio.h>

void measure(int &inches, int &feet, int &yards, int &miles, int &i);

int main()
{
   int length, inches, feet, yards, miles = 0;
   printf("Enter the length in inches:");
   scanf_s("%d", &length);
   measure(length, inches, feet, yards, miles);
   printf("Total length : %d\n", length);
   printf("Inches : %d\n", inches);
   printf("Feet : %d\n", feet);
   printf("Yards : %d\n", yards);
   printf("Miles : %d\n", miles);
   return 0;
}

void measure(int &inches, int &feet, int &yards, int &miles, int &i)
{
   int total;
   total = inches;
   feet = total / 12;
   yards = total / 36;
   miles = total / 63360;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

void measure(int *inches, int *feet, int *yards, int *miles, int *i);

int main()
{
int length, inches, feet, yards, miles = 0;
printf("Enter the length in inches:");
scanf("%d", &length);
measure(&length, &inches, &feet, &yards, &miles);
printf("Total length : %d\n", length);
printf("Inches : %d\n", inches);
printf("Feet : %d\n", feet);
printf("Yards : %d\n", yards);
printf("Miles : %d\n", miles);
return 0;
}

void measure(int * length,int *inches, int *feet, int *yards, int *miles)
{
int total;
total = *length;

// 1st we need to find the miles
*miles = total / 63360;

// than we need have only inches which are left after converting to miles
total =total %63360;

*yards = total / 36;
total=total % 36;

*feet = total / 12;
*inches=total % 12;

}

Enter the length in inches:100000 Total length : 100000 Inches : 4 Feet : 2 Yards : 1017 Miles: 1 ... Program finished with e

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Write a program that contains the function measure() that is to accept a long integer number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to reverse an integer number by using a function called reverse. The program...

    Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...

  • Distance Walked Write a program to calculate how many mile, feet, and inches a person walks...

    Distance Walked Write a program to calculate how many mile, feet, and inches a person walks a day, given the stride length in inches (the stride length is measured from heel to heel and determines how far walk with each step], the number of steps per minute, and the minutes that person walks a day. Note that 1 mile is 5280 feet and 1 feet is 12 inches. In your program, there should be the follo constants: final Int FEET_PER_MILE...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • So far I have this code but I'm not sure if it's right or how to...

    So far I have this code but I'm not sure if it's right or how to finish it. #include "distance.h" #include <iostream> #include <iomanip> #include <string> using namespace std; Distance::Distance() { feet = 0; miles = 0; yards = 0; inches = 0; } Distance::Distance(int inch) {    } Distance::Distance(int m, int y, int f, double i) { if(m < 0 || y < 0 || f < 0) { feet = 0; miles = 0; yards = 0; }...

  • **how can I make my program break if 0 is entered by user as last number...

    **how can I make my program break if 0 is entered by user as last number not always 10 numbers output should be enter 10 numbers:1 2 0 numbers entered by user are: 1 2 Largest number: 2 **arrays can ONLY be used in the main function, other than the main function pointers should be used #include #define N 10 void max(int a[], int n, int *max); int main (void) { int a [N], i , big; printf("enter %d numbers:",N);...

  • Write a complete C program for an automatic teller machine that dispenses money. The user should...

    Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense. When writing your function begin to pass your variables using pointers (or rather "pointing" to your data". Use the TimeSpace program...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • Step 4: Write a Sum Function Since we can write, compile and run simple c files,...

    Step 4: Write a Sum Function Since we can write, compile and run simple c files, lets add a bit to make a program that will sum an entire array of integers. To do this we are going to simply overwrite the main.c file to include the new function. The sum function below is not complete and must be finished before the program will execute properly. %%file main.c #include <stdio.h> int sum(int array[], int arrayLength) {     int i =...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT