Code: Select all
//simple program to convert milimeters centimeters, inches,
//feet and yards into other units by ross heatherill
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int mainselection;
int selection;
double yards, feet, inches, cm, mm, inches1, cm1, mm1, cm2, mm2, x;
feet = 3; //relative to 1 yard
inches = 36; //relative to 1 yard
cm = 91.44; //relative to 1 yard
mm = 914.4; //relative to 1 yard
inches1 = 12; //relative to 1 foot
cm1 = 30.48; //relative to 1 foot
mm1 = 304.8; //relative to 1 foot
cm2 = 2.54; //relative to 1 inch
mm2 = 25.4; //relative to 1 inch
start:
system("cls");
cout << "Hello and welcome to my simple unit converter\n\n"
<< "The interface is simple and all you need to do is\n"
<< "type in the corresponding number for\n"
<< "your selection, followed by the enter key\n\n";
cout << "Hit Enter to continue...\n\n";
getchar();
cout << "What would you like to convert into?\n\n"
<< "\n\t1. convert into yards"
<< "\n\t2. convert into feet"
<< "\n\t3. convert into inches\n\n";
cin >> mainselection;
getchar();
if (mainselection==1)
{
cout << "\nWhat would you like to convert into yards?\n\n"
<< "\n\t1. feet to yards"
<< "\n\t2. inches to yards"
<< "\n\t3. cm to yards"
<< "\n\t4. mm to yards\n\n";
cin >> selection;
getchar();
if (selection==1)
{
cout << endl<<"Convert feet to yards,";
cout << " Please enter length in feet "<<endl;
cin >> x;
yards = x / feet;
getchar();
cout << endl << setprecision(5) << x << " feet gives: " << yards << " yards\n\n";
getchar();
goto start;
}
if (selection==2)
{
cout << endl<<"Convert inches to yards,";
cout << " Please enter length in inches "<<endl;
cin >> x;
yards = x / inches;
getchar();
cout << endl << setprecision(5) << x << " inches gives: " << yards << " yards\n\n";
getchar();
goto start;
}
if (selection==3)
{
cout << endl<<"Convert cm to yards,";
cout << " Please enter length in cm "<<endl;
cin >> x;
yards = x / cm;
getchar();
cout << endl << setprecision(5) << x << " cm gives: " << yards << " yards\n\n";
getchar();
goto start;
}
if (selection==4)
{
cout << endl<<"Convert mm to yards,";
cout << " Please enter length in mm "<<endl;
cin >> x;
yards = x / mm;
getchar();
cout << endl << setprecision(5) << x << " mm gives: " << yards << " yards\n\n";
getchar();
goto start;
}}
if (mainselection==3)
{
cout << "\nWhat would you like to convert into inches today?\n\n"
<< "\n\t\t1. cm to inches"
<< "\n\t\t2. mm to inches\n\n";
cin >> selection;
getchar();
if (selection==1)
{
cout << endl<<"Convert cm to inches,";
cout << " Please enter length in cm "<<endl;
cin >> x;
inches = x / cm2;
getchar();
cout << endl << setprecision(5) << x << " cm gives: " << inches << " inches\n\n";
getchar();
goto start;
}
if (selection==2)
{
cout << endl<<"Convert mm to inches,";
cout << " Please enter length in mm "<<endl;
cin >> x;
inches = x / mm2;
getchar();
cout << endl << setprecision(5) << x << " mm gives: " << inches << " inches\n\n";
getchar();
goto start;
}}
if (mainselection==2);
{
cout << "\nWhat would you like to convert into feet today?\n\n"
<< "\n\t\t1. inches to feet"
<< "\n\t\t2. cm to feet"
<< "\n\t\t3. mm to feet\n\n";
cin >> selection;
getchar();
if (selection==1)
{
cout << endl<<"Convert inches to feet,";
cout << " Please enter length in inches "<<endl;
cin >> x;
feet = x / inches1;
getchar();
cout << endl << setprecision(5) << x << " inches gives: " << feet << " feet\n\n";
getchar();
goto start;
}
if (selection==2)
{
cout << endl<<"Convert cm to feet,";
cout << " Please enter length in cm "<<endl;
cin >> x;
feet = x / cm1;
getchar();
cout << endl << setprecision(5) << x << " cm gives: " << feet << " feet\n\n";
getchar();
goto start;
}
if (selection==3)
{
cout << endl<<"Convert mm to feet,";
cout << " Please enter length in mm "<<endl;
cin >> x;
feet = x / mm1;
getchar();
cout << endl << setprecision(5) << x << " mm gives: " << feet << " feet\n\n";
getchar();
goto start;
}}
getchar();
return 0;
}
updated code and file 24/11/2010