3rd C++ program

c, c++, php, html, sql ..etc discussion. also includes codes and source codes.
Post Reply
PinPoint
Special
Special
Posts: 124
Joined: Wed Dec 03, 2008 6:41 pm

3rd C++ program

Post by PinPoint »

3rd program done by head after a few hours of learning C++

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
Attachments
multi measurement converter.rar
(105.65 KiB) Downloaded 774 times
Last edited by PinPoint on Wed Nov 24, 2010 2:09 am, edited 2 times in total.
User avatar
Sethioz
Admin
Admin
Posts: 4764
Joined: Fri Jul 27, 2007 5:11 pm
Custom: Gaming YT > https://youtube.com/SethiozEntertainment
Game Hacking YT > https://youtube.com/sethioz
Game Hacks Store > https://sethioz.com/shopz
Location: unknown
Contact:

Re: 3rd C++ program

Post by Sethioz »

dont think it works. it said that 188cm is about 2.022 feet, but actually its 188 centimetres = 6.167979 feet.
i only tested one option tho.
PinPoint
Special
Special
Posts: 124
Joined: Wed Dec 03, 2008 6:41 pm

Re: 3rd C++ program

Post by PinPoint »

k ive updated the code and file, i know what i done wrong. i needed to change the formula altogether or add more variables so i added more variables and changed the formula to suit

all works good now
Post Reply