Newbie converting distance errors

Hey guys, brand new to this and have to write a program for converting distances displaying labels, and numbers with 3 digits to the right of the decimal. Keep getting errors for expected constructor, destructor, or type conversion and undeclared variables. I've tried to make multiple changes and keep getting errors, so any help would be greatly appreciated.

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

// constants

constant double m = miles
constant double f = m*5280.0; // feet = miles*5280.0
constant double i = f*12.0; // inches = feet*12.0
constant double c = i*2.54; // centimeters = inches*2.54
constant double r = c/100; // meters = centimeters/100
constant double k = r/1000; // kilometers = meters/1000

int main()

{

//variable
variable double m; //distance in miles

cout << "Enter distance in miles";

// convert to feet
cin >> m;
cout << fixed;
cout << setprecision(3) << m << endl;
cout << m << "miles is" << endl << f << "feet" << endl;

// convert to inches
cout << fixed;
cout << setprecision(3) << f << endl;
cout << f << "feet is" << endl << i << "inches" << endl;

// convert to centimeters
cout << fixed;
cout << setprecision(3) << i << endl;
cout << i << "inches is" << endl << c << "centimeters" << endl;

// convert to meters
cout << fixed;
cout << setprecision(3) << c << endl;
cout << c << "centimeters is" << endl << r << "meters" << endl;

// convert to kilometers
cout << fixed;
cout << setprecision(3) << r << endl;
cout << r << "meters is" << endl << k << "kilometers" << endl;

return 0;

}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>

// conversion constants
const double feet_per_mile = 5280.0; // feet = miles*5280.0
const double inches_per_feet = 12.0; // inches = feet*12.0
const double centimeters_per_inch = 2.54; // centimeters = inches*2.54
// etc.

int main()
{
    double miles ;
    std::cout << "distance in miles? " ;
    std::cin >> miles ;

    const double feet = miles * feet_per_mile ;
    const double inches = feet * inches_per_feet ;
    const double cms = inches * centimeters_per_inch ;

    std::cout << std::fixed << std::setprecision(2) << miles << " miles  "
              << feet << " feet  " << inches << " inches  " << cms << " cms\n" ;
}
Topic archived. No new replies allowed.