-
converting meausements
Call By Reference and Call By Value
i have to write a program to convert inches and feet to meters and centimetres and the other way also. My friend said he is doing it using and if else statement a loop to repeat ive tryed it my own way but cant get it to work :/ any ideas on how to do this can functions be used?
Code:
/* Program to convert length to different units*/
#include<stdio.h>
int main(void)
{
float length, converted, measure;
char inUnits, outUnits;
printf("Enter the value of length to be converted: ");
scanf("%f", &measure);
printf("Enter the unit of value entered (I, F, C, or M): ");
scanf("%c", &inUnits);
printf("Enter the unit to convert value to (c, m, f, or i ): ");
scanf("%c", &outUnits);
switch(inUnits){
case 'I':
converted = measure * 2.54001;
printf("The length you entered in inches is equal to %f centimeters", converted);
break;
case 'M':
converted = measure * 3.3;
printf("The length you entered in meters is equal to %f feet", converted);
break;
case 'F':
switch(outUnits){
default:
printf("Incorrect unit entered. Please enter a valid unit.");
break;}
break;
default:
printf("Incorrect unit entered. Please enter a valid unit.");
break;}
return 0;
}
-
Presumably the conversion factor needed depends both on the input units and output units. You code only shows dependence on input units.
Then, if you want to repeat the process, add a loop construct.