Celsius and fahrenheit converter.

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

Celsius and fahrenheit converter.
  1. Unread #1 - Jul 4, 2007 at 1:45 AM
  2. Ginsued
    Referrals:
    0

    Ginsued Guest

    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;
    }
     
  3. Unread #2 - Jul 4, 2007 at 11:44 AM
  4. eagles358
    Referrals:
    0

    eagles358 Guest

    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.
     
  5. Unread #3 - Jul 5, 2007 at 12:53 AM
  6. Ginsued
    Referrals:
    0

    Ginsued Guest

    Celsius and fahrenheit converter.

    Good idea, thanks. I'll add it tonight..try anyway. xD
     
  7. Unread #4 - Jul 5, 2007 at 4:02 PM
  8. eagles358
    Referrals:
    0

    eagles358 Guest

    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...

    }
     
  9. Unread #5 - Jul 5, 2007 at 4:19 PM
  10. Ginsued
    Referrals:
    0

    Ginsued Guest

    Celsius and fahrenheit converter.

    Thanks.
     
  11. Unread #6 - Jul 5, 2007 at 6:35 PM
  12. eagles358
    Referrals:
    0

    eagles358 Guest

    Celsius and fahrenheit converter.

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

Users viewing this thread
1 guest


 
 
Adblock breaks this site