Support Forums
Celsius and Farenheit Converter - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Celsius and Farenheit Converter (/showthread.php?tid=5434)



Celsius and Farenheit Converter - uber1337 - 03-30-2010

This is my first C++ program and all it does is convert Fahrenheit to Celsius and vise versa, tell me what you guys think or if there is anything I can improve on.
Code:
/*
This is my first C++ program,
it converts C to F and vise versa,
made by uber1337
*/

#include <iostream>
using namespace std;

int main ()
{
    int choice;
    cout << "1.) Celsius to Fahrenheit" << endl;
    cout << "2.) Fahrenheit to Celsius" << endl;
    cout << "What would you like to do?:" << endl;
    cin >> choice;
    if (choice == 1)
    {
        float celsius, fahrenheit;
        cout << "Enter degrees in Celsius:" << endl;
        cin >> celsius;
        fahrenheit = ((celsius * 9.0) / 5.0) + 32.0;
        cout << celsius << " Degrees Celsius is equal to " << fahrenheit << " degrees Fahrenheit" << endl;
        cin >> celsius; //So the windows doesn't disapear
    }              
    else if (choice == 2)
    {
        float celsius, fahrenheit;
        cout << "Enter degrees in Fahrenheit:" << endl;
        cin >> fahrenheit;
        celsius = ((fahrenheit - 32) / 9) * 5;
        cout << fahrenheit << " Degrees Fahrenheit is equal to " << celsius << " degrees Celsius" << endl;
        cin >> celsius; //So the windows doesn't disapear
    }
    else
    {
        cout << "You have entered an incorrect option";
    }
}

Blackhat


RE: Celsius and Farenheit Converter - Canoris - 03-30-2010

(03-30-2010, 08:58 AM)uber1337 Wrote: This is my first C++ program and all it does is convert Fahrenheit to Celsius and vise versa, tell me what you guys think or if there is anything I can improve on.
Code:
/*
This is my first C++ program,
it converts C to F and vise versa,
made by uber1337
*/

#include <iostream>
using namespace std;

int main ()
{
    int choice;
    cout << "1.) Celsius to Fahrenheit" << endl;
    cout << "2.) Fahrenheit to Celsius" << endl;
    cout << "What would you like to do?:" << endl;
    cin >> choice;
    if (choice == 1)
    {
        float celsius, fahrenheit;
        cout << "Enter degrees in Celsius:" << endl;
        cin >> celsius;
>>>     fahrenheit = ((celsius * 9.0) / 5.0) + 32.0;
        cout << celsius << " Degrees Celsius is equal to " << fahrenheit << " degrees Fahrenheit" << endl;
        cin >> celsius; //So the windows doesn't disapear
    }              
    else if (choice == 2)
    {
        float celsius, fahrenheit;
        cout << "Enter degrees in Fahrenheit:" << endl;
        cin >> fahrenheit;
        celsius = ((fahrenheit - 32) / 9) * 5;
        cout << fahrenheit << " Degrees Fahrenheit is equal to " << celsius << " degrees Celsius" << endl;
        cin >> celsius; //So the windows doesn't disapear
    }
    else
    {
        cout << "You have entered an incorrect option";
    }
}

Blackhat
I'm not familiar with C++, but I can safely say you have left out a ')' in line 22.


RE: Celsius and Farenheit Converter - Unfaithful - 03-30-2010

Hah this would help me at my Physic test xD


RE: Celsius and Farenheit Converter - uber1337 - 03-30-2010

(03-30-2010, 02:25 PM)Μαύρο Wrote: I'm not familiar with C++, but I can safely say you have left out a ')' in line 22.
Heh maybe you should take another look.
Code:
fahrenheit = ((celsius * 9.0) / 5.0) + 32.0;



RE: Celsius and Farenheit Converter - Canoris - 03-31-2010

Aye, bad mistake. Confusing looking at code gray-gray.


RE: Celsius and Farenheit Converter - Fallen - 04-05-2010

On windows you can use _getch(); for the "window not disappearing" effect.


RE: Celsius and Farenheit Converter - FiLTHY - 05-20-2010

Never knew those formulas to convert Thanks allot .


RE: Celsius and Farenheit Converter - mmki - 06-08-2010

Nice code bro Smile thanks tons