/* convert6.c
This program converts integers given by the user from the English
unit of measure, inches, to the Metric System units; cm, m, and km.
The user can enter whatever value the wish to convert. The program
will exit when a -1 is entered.
This program may not reflect all the requirements of the C Coding
Standards used in this class.
*/
#include
int main() {
int inches;
float meters;
/* Priming Read */
printf("This program will convert inches into the Metric System.\n");
printf("Please enter an integer (-1 to End): ");
scanf("%d", &inches);
/* Sentinel Value: -1 */
while(inches != -1) {
meters = inches * .0254;
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);
printf("\nPlease enter another integer (-1 to End): ");
scanf("%d", &inches);
}
return(0);
}
[foxtrot]> cc convert6.c
[foxtrot]> a.out
This program will convert inches into the Metric System.
Please enter an integer (-1 to End): 4
Conversion of 4 inches into metric yields:
10.160 centimeters
0.102 meters
0.000 kilometers
Please enter another integer (-1 to End): 7
Conversion of 7 inches into metric yields:
17.780 centimeters
0.178 meters
0.000 kilometers
Please enter another integer (-1 to End): -1
[foxtrot]>