Adblock breaks this site

Celsius and fahrenheit converter.

Discussion in 'Programming General' started by Ginsued, Jul 4, 2007.

  1. Ginsued

    Ginsued Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    With the help of The End I was able to write this as my first C++ program.
    It converts both Fahrenheit to Celsius and Celsius to Fahrenheit.
    I found it useful so i though I'd post it.
    First the .exe: http://files.filefront.com/Conversionexe/;7957265;;/fileinfo.html

    Now the code.
    Code:
    #include <iostream>
    using namespace std;
    
    int main(void)
    {
       double fahrenheit,celsius,choice;
       start:
       cout << "Please choose what you want to do. " << endl;
       cout << "1) Fahrenheit to Celsius. " << endl;
       cout << "2) Celsius to Fahrenheit. " << endl << endl;
       cin >> choice;
       if (choice == 1)
       {
       cout << "Enter degree in Fahrenheit: ";
       cin >> fahrenheit;
    //convert
    celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
       cout << "The degrees in Celsius is: " << celsius << endl;
       system("pause");
       return 0;
       }
       if (choice == 2)
       {
       cout << "Enter degree in Celsius: ";
       cin >> celsius;
    //convert
    fahrenheit = ((celsius * 9.0) / 5) + 32;
       cout << "The degrees in Fahrenheit is: " << fahrenheit << endl;
       system("pause");
       }
       else {
    	   cout << "Invalid option, please try again." << endl;
    	   goto start;
       }
       return 0;
    }
     
  2. eagles358

    eagles358 Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    nice job, this was one of my first programs also.

    If you are looking for a way to improve it, try making the whole thing an infinite loop, that repeats until told to stop, for example

    0) exit
    1) farenheit to celsius
    2) celsius to farenheit

    and the program repeats until the user entered 0.

    this way you can find multiple temperatures without having to open up the program everytime.
     
  3. Ginsued

    Ginsued Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    Good idea, thanks. I'll add it tonight..try anyway. xD
     
  4. eagles358

    eagles358 Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    try somthing like this:

    while(1) { //infinite loop
    cout<<"enter number...";
    cin>>n;
    if (n=0)
    break;
    else if (n=1)
    farenheit to celsius code.....
    else if (n=2)
    ceclius farenheit code...

    }
     
  5. Ginsued

    Ginsued Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    Thanks.
     
  6. eagles358

    eagles358 Guest

    Referrals:
    0
    Celsius and fahrenheit converter.

    sure np
     
< SidNET (Web Browser in C#) Source Released! | Dev-C++ help >


 
 
Adblock breaks this site