Assignment 1.3 : Variable, Operator and Expression SET 3 SOLUTION
1> Write a program that takes length as input in feet and inches. The program should then convert the lengths in centimeters and display it on screen. Assume that the given lengths in feet and inches are integers.
/******************************************************** Purpose :This program converts measurements in feet and inches into centimeters. ********************************************************/ #include <iostream.h> //Header file const double CENTIMETERS_PER_INCH = 2.54; //Named constants const int INCHES_PER_FOOT = 12; //Named constants int main () { int feet, inches; int totalInches; double centimeter; cout << "Enter two integers, one for feet and one for inches: "; cin >> feet >> inches; cout << endl; cout << "The numbers you entered are " << feet << " for feet and " << inches << " for inches. " << endl; totalInches = INCHES_PER_FOOT * feet + inches; cout << "The total number of inches = " << totalInches << endl; centimeter = CENTIMETERS_PER_INCH * totalInches; cout << "The number of centimeters = " << centimeter << endl; return 0; }
No comments:
Post a Comment