Write a program that takes length as input in feet and inches and convert it into centimeters. Using the constant for declaration of conversion constants. To calculate the equivalent length in centimeters, you need to multiply the total inches by 2.54. Similarly, to find the total inches, you need to multiply the feet by 12 and add the inches.
#include <iostream>
using namespace std;
const int INCH_PER_FOOT=12;
const double CM_PER_INCH=2.54;
int main() {
int inches, feet;
cout << "Enter a length in foot and inches: ";
cin >> feet >> inches;
int tot_inch = inches + INCH_PER_FOOT * feet;
double cm = tot_inch * CM_PER_INCH;
cout << "It is equal " << cm << " cm";
return 0;
}
Comments
Leave a comment