1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Do while in unit converter

Discussion in 'C' started by osadalakimdi, May 20, 2011.

  1. osadalakimdi

    osadalakimdi New Member

    Joined:
    May 20, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Please Help me ,I want to use "do while", my every conversion run until I press a key then it goes its own option like I want when I complete my temperature Celsius conversion its keep running until I press a key then it goes temperature conversion options and same thing in other conversions, please help me

    here is a complete code

    Code:
    #include <iostream>
    #include <conio.h>
    #include <process.h>
    #include <iomanip>
    using namespace std;
    //INLINE FUNCTIONS
                                                        //Design
                                                        void starline()
                                                        {
                                                             for(int i=0;i<80;i++)
                                                             cout<<"*";
                                                             }
                                                        
                                                   
     //TEMPERATURE
    
    //CELCIUS TO FAHRENHEIT 
    
    void CtoF()
    {
             
       double CtoF;   
       cout << "\nCelsius: ";
       cin >> CtoF;
       cout << endl << "Conversion:\n" << CtoF << " C      is      " << ((CtoF * 1.8) + 32) << " F \n";
    }
    
    
    
    
    
    
    //FAHRENHEIT TO CELCIUS 
    void FtoC()
    {
       double FtoC;
       cout << "\nFahrenheit: ";
       cin >> FtoC;
       cout << endl << "Conversion:\n" << FtoC << " F      is      " << ((FtoC - 32) * 1.8) << " C \n";
    }
    //CELCIUS TO KELVIN
    void CtoK()
    {
       double CtoK;
       cout << "\nCelsius: ";
       cin >> CtoK;
       cout << endl << "Conversion:\n" << CtoK << " C      is      " << (CtoK + 273) << " K \n";
    }
    // KELVIN TO CELCIUS 
    void KtoC()
    {
       double KtoC;
       cout << "\nKelvin: ";
       cin >> KtoC;
       cout << endl << "Conversion:\n" << KtoC << " K      is      " << (KtoC - 273) << " C \n";
    }
    // KELVIN TO FAHRENHEIT
    void KtoF()
    {
       double KtoF;
       cout << "\nKelvin: ";
       cin >> KtoF;
       cout << endl << "Conversion:\n" << KtoF << " K      is      " << 1.8*(KtoF - 273)+32 << " F \n";
    }
    //FAHRENHEIT TO KELVIN
    void FtoK()
    {
       double FtoK;
       cout << "\nFahrenheit: ";
       cin >> FtoK;
       cout << endl << "Conversion:     " << FtoK << " F      is      " << 0.55*(FtoK - 32)+273 << " K \n";
    }
    
    
                                                     //LENGTH
    //Miles to Kilometer
    void Mi_Km()
    {
       double Mi_Km;
       cout << "\nMiles: ";
       cin >> Mi_Km;
       cout << endl << "Conversion:     " << Mi_Km<< " Miles      is      " << Mi_Km*1.609<< " Km \n";
    }
    //Inches to Millimeter
    void In_MM()
    {
       double In_MM;
       cout << "\nInches: ";
       cin >> In_MM;
       cout << endl << "Conversion:     " << In_MM<< " Inch  is      " << In_MM*25.4<< " mm \n";
    }
    //Inches to Centimeter
    void In_Cm()
    {
       double In_Cm;
       cout << "\nInches: ";
       cin >> In_Cm;
       cout << endl << "Conversion:     " << In_Cm<< " Inch  is      " << In_Cm*2.54<< " cm \n";
    }
    
    //Foot to Centimeter
    void Ft_Cm()
    {
       double Ft_Cm;
       cout << "\nFoot: ";
       cin >> Ft_Cm;
       cout << endl << "Conversion:     " << Ft_Cm<< " Foot  is      " << Ft_Cm*30.48<< " cm \n";
    }
    //Meter to Centimeter
    void M_Cm()
    {
       double M_Cm;
       cout << "\nMeter: ";
       cin >> M_Cm;
       cout << endl << "Conversion:     " << M_Cm<< " Meter  is      " << M_Cm*100<< " cm \n";
    }
    //Foot to Meter
    void Ft_M()
    {
       double Ft_M;
       cout << "\nFoot: ";
       cin >> Ft_M;
       cout << endl << "Conversion:     " << Ft_M<< " Foot  is      " << Ft_M*0.3048<< " m \n"; 
    }
    //Yard to Meter
    void Yrd_M()
    {
       double Yrd_M;
       cout << "\nYard: ";
       cin >> Yrd_M;
       cout << endl << "Conversion:     " << Yrd_M<< " Yard  is      " << Yrd_M*0.9144<< " m \n"; 
    }
                                                     //AREA
    //Square Foot  to Square Meter                                              
    void SqrF_SqrM()
    {
       double SqrF_SqrM;
       cout << "\nSquare Foot: ";
       cin >> SqrF_SqrM;
       cout << endl << "Conversion:     " << SqrF_SqrM<< " Sq.F  is      " << SqrF_SqrM*0.092903 << " Sq.m \n"; 
    }      
    
    //Square Yard  to Square Meter                                              
    void SqrY_SqrM()
    {
       double SqrY_SqrM;
       cout << "\nSquare Yard: ";
       cin >> SqrY_SqrM;
       cout << endl << "Conversion:     " << SqrY_SqrM<< " Sq.Yrd  is      " << SqrY_SqrM*0.8361274 << " Sq.m \n"; 
    }                                        
                                                     
    //Mile Square to Kilometer Square
    void SqrMi_SqrKm()
    {
       double SqrMi_SqrKm;
       cout << "\nSquare Miles ";
       cin >> SqrMi_SqrKm;
       cout << endl << "Conversion:     " << SqrMi_SqrKm << " Sq.Miles is      " << SqrMi_SqrKm*2.5899881 << " Sq.km \n"; 
    }   
    //Inch Square to Centimeter Square
    void SqrIn_SqrCm()
    {
       double SqrIn_SqrCm;
       cout << "\nSquare Inch ";
       cin >> SqrIn_SqrCm;
       cout << endl << "Conversion:     " << SqrIn_SqrCm << " Sq.Inch  is      " << SqrIn_SqrCm*6.4516 << " Sq.Cm \n"; 
    }   
    
    //Hectare to Mile Square
    void Hect_SqrMi()
    {
       double Hect_SqrMi;
       cout << "\nHectare:";
       cin >> Hect_SqrMi;
       cout << endl << "Conversion:     " << Hect_SqrMi << " Hectare is      " << Hect_SqrMi*0.003861 << " Sq.Mi \n"; 
    } 
    
    //Acre to Kilometer Square
    void Acr_SqrKm()
    {
       double Acr_SqrKm;
       cout << "\nAcre:";
       cin >> Acr_SqrKm;
       cout << endl << "Conversion:     " << Acr_SqrKm << " Acre is      " << Acr_SqrKm*0.0040469 << " Sq.Km \n"; 
    } 
    
    //Acre to Hectare
    void Acr_Hect()
    {
       double Acr_Hect;
       cout << "\nAcre:";
       cin >> Acr_Hect;
       cout << endl << "Conversion:     " << Acr_Hect << " Acre is      " << Acr_Hect*.4046856 << " Hect \n"; 
    } 
                                                      //Weight
    //Pound to Kilogram
    void lbs_Kg()
    {
       double lbs_Kg;
       cout << "\nPound:";
       cin >> lbs_Kg;
       cout << endl << "Conversion:     " << lbs_Kg << " Pound is      " << lbs_Kg*0.4535924 << " Kg \n"; 
    } 
    
    
    
    //Carat to Gram
    void Ct_g()
    {
       double Ct_g;
       cout << "\nCarat:";
       cin >> Ct_g;
       cout << endl << "Conversion:     " << Ct_g << " Carat is      " << Ct_g*0.2 << " g \n"; 
    } 
    
    
    
    //Ounce to Gram
    void Oz_g()
    {
       double Oz_g;
       cout << "\nOunce:";
       cin >> Oz_g;
       cout << endl << "Conversion:     " << Oz_g << " Carat is      " << Oz_g*28.349 << " g \n"; 
    } 
    
                                             //Volume
    //Inch cube to Centimeter Cube
    
    void Cu_in_Cu_cm()
    {
       double Cu_in_Cu_cm;
       cout << "\nCubic inch:";
       cin >> Cu_in_Cu_cm;
       cout << endl << "Conversion:     " << Cu_in_Cu_cm<< " Cubic Inch is      " << Cu_in_Cu_cm*16.387 << " Cu.cm \n"; 
    } 
    //Foot Cube to Meter Cube
    void Cu_Ft_Cu_m()
    {
       double Cu_Ft_Cu_m;
       cout << "\nCubic Feet:";
       cin >> Cu_Ft_Cu_m;
       cout << endl << "Conversion:     " << Cu_Ft_Cu_m<< " Cubic Feet is      " << Cu_Ft_Cu_m*0.0283 << " Cu.m \n"; 
    } 
    
    //Yard Cube to Meter Cube
    void Cu_Yrd_Cu_m()
    {
       double Cu_Yrd_Cu_m;
       cout << "\nCubic Yard:";
       cin >> Cu_Yrd_Cu_m;
       cout << endl << "Conversion:     " << Cu_Yrd_Cu_m << " Cubic Yard is      " << Cu_Yrd_Cu_m*0.764 << " Cu.m \n"; 
    } 
    
    //START MAIN PROGRAM
    int main()
    {
        starline();    
        cout<<endl;
        cout <<setw(50)<< "UNIVERSAL CONVERTER BETA.\n";
        cout<<endl;
        starline();
      
          cout <<"\nChoose Option Then Press Enter (q to quit)\n\n"
                <<"\n1. Temperature \n"            
                <<"2. Length \n"
                <<"3. Area \n"
                <<"4. Weight \n"
                <<"5. Volume \n";      
    
              
          int choice; 
          int temp;
          int len;
                             
              cout << "\nOption: ";
              cin >> choice;       
           //for Temperature  
           switch(choice)
           {
            case 1: cout<<"\nChoose Option Then Press Enter (q to quit)\n\n"
                        <<"1. Celcuis to Fahrenheit \n"
                        <<"2. Fahrenheit to Celcuis \n"
                        <<"3. Celcuis to Kelvin \n"
                        <<"4. Kelvin to Celcuis \n"
                        <<"5. Kelvin to Fahrenheit \n"
                        <<"6. Fahrenheit to Kelvin \n"
                        << "\nOption: ";
                        cin>> temp; 
                  //switch for temperature  
                 switch(temp)
                 {
                 case 1:                  
                      CtoF();break;   
                 case 2:
                      FtoC();break; 
                 case 3:
                      CtoK();break; 
                 case 4:     
                      KtoC();break; 
                 case 5:     
                      KtoF();break;
                 case 6:     
                      FtoK();break;
                      
                             }
                 break;
                 
            case 2: cout<<"\nChoose Option Then Press Enter (q to quit)\n\n"
                        <<"1. Miles to Kilometer \n"
                        <<"2. Inches to Millimeter \n"
                        <<"3. Inches to Centimeter \n"
                        <<"4. Foot to Centimeter \n"
                        <<"5. Meter to Centimeter \n"
                        <<"6. Foot to Meter \n"
                        <<"7. Yard to Meter \n"
                        << "\nOption: ";
                        cin>>len;
                           switch(len)
                 {
                 case 1:
                      Mi_Km();break;   
                 case 2:
                      In_MM();break; 
                 case 3:
                      In_Cm();break; 
                 case 4:     
                      Ft_Cm();break; 
                 case 5:     
                      M_Cm();break;
                 case 6:     
                      Ft_M();break;
                 case 7:     
                      Yrd_M();break;            
                      
                             }
                 break;
                 case 3: cout<<"\nChoose Option Then Press Enter (q to quit)\n\n"
                        <<"1. Square Feet  to Square Meter  \n"
                        <<"2. Yard Square to Meter Square \n"
                        <<"3. Mile Square to Kilometer Square\n"
                        <<"4. Inch Square to Centimeter Square\n"
                        <<"5. Acre to Kilometer Square \n"
                        <<"6. Hectare to Mile Square \n"                    
                        <<"7. Acre to Hectare \n"
                        << "\nOption: ";
                        
                        cin>>len;
                           switch(len)
                 {
                 case 1:
                      SqrF_SqrM();break;   
                 case 2:
                      SqrY_SqrM();break; 
                 case 3:
                      SqrMi_SqrKm();break; 
                 case 4:     
                      SqrIn_SqrCm();break; 
                 case 5:     
                      Acr_SqrKm();break;
                 case 6:     
                      Hect_SqrMi();break;
                 case 7:     
                      Acr_Hect();break;            
                      
                             }
                 break;
                 
                 case 4: cout<<"\nChoose Option Then Press Enter (q to quit)\n\n"
                             <<"1. Pound to Kilogram  \n"
                             <<"2. Carat to Gram \n"
                             <<"3. Ounce to Gram\n"                  
                             << "\nOption: ";
                        
                        cin>>len;
                           switch(len)
                 {
                 case 1:
                      lbs_Kg();break;   
                 case 2:
                      Ct_g();break; 
                 case 3:
                      Oz_g();break; 
                           
                      
                             }
                 break;
                 
                  case 5: cout<<"\nChoose Option Then Press Enter (q to quit)\n\n"
                             <<"1. Cubic Inch to Cubic Centimeter  \n"
                             <<"2. Cubic Foot to Cubic Meter \n"
                             <<"3. Cubic Yard to Cubic Meter\n"                  
                             << "\nOption: ";
                        
                        cin>>len;
                           switch(len)
                 {
                 case 1:
                      Cu_in_Cu_cm();break;   
                 case 2:
                      Cu_Ft_Cu_m();break; 
                 case 3:
                      Cu_Yrd_Cu_m();break; 
                           
                      
                             }
                 break;
                                  
            }
            
           //EXIT 
       cout << "\nPress Y to make another conversion, or N to exit the program\n";
       char yn;
       cin >> yn;
       if (yn == 'y' || yn == 'Y')
          {
          cout << "\n\n\n";
          main();
          }
         
       else cout << "Good Bye! (Type any key and press enter to exit)";
           
           
           getch();
           return 0;
        }
     
    Last edited by a moderator: May 21, 2011

Share This Page