/* convert2.c
This program converts an integer greater than 100 given by the user
from the English unit of measure, inches, to the Metric System units;
cm, m, and km. If a number less than 100 is input, the program exits.
This program may not reflect all the requirements of the C Coding
Standards used in this class.
*/
#include
int main() {
int inches;
float meters;
printf("This program will convert inches into the Metric System.\n");
printf("Please enter an integer greater than 100: ");
scanf("%d", &inches);
/* If the integer entered is less than 100, the input is invalid.
Return to exit the program. */
if(inches < 100) {
printf("Integer must be greater than 100. Good Bye!\n");
return(1);
}
meters = inches * .0254;
/* Notice the neat special symbols below. There is a table in your
book. Check it out. Very Useful. */
printf("Conversion of %d inches into metric yields:\n", inches);
printf("\t\t%.3f centimeters\n", meters * 100);
printf("\t\t%.3f meters\n", meters);
printf("\t\t%.3f kilometers\n", meters / 1000);
return(0);
}
[foxtrot]> cc convert2.c
[foxtrot]> a.out
This program will convert inches into the Metric System.
Please enter an integer greater than 100: 5
Integer must be greater than 100. Good Bye!
[foxtrot]> a.out
This program will convert inches into the Metric System.
Please enter an integer greater than 100: 102
Conversion of 102 inches into metric yields:
259.080 centimeters
2.591 meters
0.003 kilometers
[foxtrot]>