1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <cmath>
using namespace std;
void input(int& inFeet, int& inInches);
//two parameters of type int, no restriction on values other than that of type int
//inFeet is number of feet
//inInches is number of inches
void conversion(int conFeet, int conInches, double& conMetres, double& conCentimetres);
//4 parameters, 2 of type int and two of type double
//conFeet is number of feet user has input
//conInches is number of inches user has input
//conMetres is the toal number of inches from the sum of conFeet and conInches converted
to metres
//conCentimetres is the remaining decimal from conMetres
void output(double outMetres, double outCentimetres);
//two parameters of type double
//outputs the users input of feet and inches in metres and centimetres
int main()
{
int feet, inches;
double metres, centimetres;
char ans;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do
{
input(feet, inches);
conversion(feet, inches, metres, centimetres);
output(metres, centimetres);
cout << "Again (Y/N)? ";
cin >> ans;
}while( ans == 'y' || ans == 'Y');
return 0;
void input(int& inFeet, int& inInches)
{
cout << "Please input your length in feet (asked for inches next): ";
cin >> inFeet;
cout << "and now the remaining inches: ";
cin >> inInches;
}
void conversion(int conFeet, int conInches, double& conMetres, double& conCentimetres)
{
const double metresToFeet = 0.3048;
const double inchesToCm = 2.54;
double totalCm, totalM;
totalCm = (conInches + (12 * conFeet)) * inchesToCm;
totalM = totalCm/100;
conCentimetres = modf(totalM, &conMetres) * 100;
void output(double outMetres, double outCentimetres)
{
cout << "This is the equivalent of " << outMetres << "M " << outCentimetres
<< "cm" << endl;
}
|