1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*
Problem A: Write a C program to prompt and input from the user a height in feet and inches.
Calculate and print the equivalent height in inches, centimeters and meters,
(printed to the nearest 1000th) but you MUST do the following.
Use a separate function for each conversion that calculates
and returns (through a return statement) the following measurements:
" one function converting from feet and inches (parameters)
to inches (return value)-- there are 12 inches per foot
" one function from inches (parameter) to centimeters (return value)--
there are 2.54 centimeters per inch
" one function from inches (parameter) to meters (return value)--
there are 100 centimeters per meter
Call that function in main. Use the following equivalences,
but figure out the equations based on these (these are NOT the calculations):
Use a function (call from main) to print the input feet & inches and equivalent inches,
centimeters and meters (with labels -- see test runs).
Use the following input to turn in: 6 2 (for feet & inches),
in another run: 4 11 (for feet & inches), in another run: 5 6 (for feet & inches).
*/
#include <stdio.h>
#include <stdlib.h>
float getInchesFeet (float inches, float feet);
float feetToInch (float feet, float inches);
float inchToCMeter (float inches, float cmeters);
float inchToMeter (float inches, float meters);
int main (void)
{
// local definitions
// statements
getInchesFeet (float inches, float feet);
printf("%d feet and %d inch(es) is equal to:\n", feet, inches);
getTotalInches (float feetToInches, float totalInches);
inchToCMeter (float inches, float cmeters);
inchToMeter (float inches, float meters);
printf("%6.3f inches\n", toalInches);
printf("%6.3f centimeters\n", cmeters);
printf("%6.3f meters\n", meters);
system("pause");
return 0;
}
/* ======= getInchesFeet =========
Asks user to input inches
*/
getInchesFeet (float feet, float inches);
printf("Welcome, please input the feet and and inches in "n n" format: ");
scanf("%d %d", &feet, &inches);
return (feet, inches);
/* ======= feetToInch ========
Converts feet to inches
Pre
Post
*/
float getTotalInches (float feetToInches, float totalInches)
{
// Local declarations
float feetToInches;
float totalInches;
getInchesFeet (float feet, float inches);
feetToInches = feet * 12;
totalInches = inches + feetToInches;
return totalInches;
} // feetToInch
float inchToCMeter (float inches, float cmeters)
{
// Local declarations
float inches;
float cmeters;
getTotalInches (float feetToInches, float totalInches)
cmeters = totalInches * 2.54;
return cmeters;
} // inchToCMeter
float inchToMeter (float inches, float meters)
{
// Local declarations
float inches;
float meters;
getTotalInches (float feetToInches, float totalInches)
meters = totalInches * 0.0254;
return meters;
} // inchToMeter
|