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
|
double meter_to_inches (double meters);
double meter_to_yards (double meters);
double meter_to_miles(double meters);
void display_mi_yd_in (double meters, double inches, double miles, double yards);
//dispaly meteres as miles, yards, and inches, rounded to nearest inch
int main()
{
int iterations, m;
double mi, yd, in;
cout << "Enter the number of calculations to be performed. ";
cin >> iterations;
for (int i=1; i <= iterations; i = i + 1)
{
cout << "Enter the number of meters. ";
cin >> m;
mi = meter_to_miles(m);
yd = meter_to_yards(m);
in = meter_to_inches(m);
display_mi_yd_in(m, mi, yd, in);
}
return 0;
}
double meter_to_miles(double meters)
{
return meters / 1609.344;
}
double meter_to_inches(double meters)
{
return meters * 39.3701;
}
double meter_to_yards(double meters)
{
return meters * 1.093613;
}
void display_mi_yd_in(double meters, double miles, double yards, double inches)
{
double m, y, i;
m = yards / 1760;
y = fmod(yards, 1760);
i = y / 36;
cout << meters << " meters is " << m << " miles " << y << " yards and " << i << " inches" << endl;
}
|