S
Srdja123
Im doing some C++ exercises from the Primer plus book by Prata. So
anyway, the assignment is to convert meters and centimeters to inches
and foot and so on.
I just dont know how to make the variable "tum" to show feet and
inches. I know that I can use cmath and fmod(a, b), and then use
double as a type, but is there any other way to the solution?
All help is appreciated!
anyway, the assignment is to convert meters and centimeters to inches
and foot and so on.
Code:
#include <iostream>
int meterTillCm(int);
double cmTillTum(double);
int main()
{
using namespace std;
cout << "Type in your length in m and cm \n";
cout << "Meter: ";
int meter;
cin >> meter;
int meterIcm;
meterIcm = meterTillCm(meter);
cout << "Centimeter: ";
int cm;
cin >> cm;
int alltIcm;
alltIcm = meterIcm + cm;
cout << "You are: " << alltIcm << " cm tall\n";
double tum;
tum = cmTillTum(alltIcm);
cout << "You are: " << tum << " inch tall\n";
double fot;
double tum2;
const int inch_per_foot = 12;
fot = tum / inch_per_foot;
tum2 = tum % inch_per_foot);
cout << "Foot: " << fot << " and " << tum2 << " inch.";
cin.get();
cin.get();
return 0;
}
int meterTillCm(int n)
{
return n *100;
}
double cmTillTum(double n)
{
return n / 2.54;
}
I just dont know how to make the variable "tum" to show feet and
inches. I know that I can use cmath and fmod(a, b), and then use
double as a type, but is there any other way to the solution?
All help is appreciated!