Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Celsius and Farenheit Converter
#1
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
[Image: izsyo6.jpg]


Reply
#2
(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.
Do what thou wilt shall be the whole of the Law. Love is the law, love under will.
.::The Rights of Man::.
Reply
#3
Hah this would help me at my Physic test xD
Reply
#4
(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;
[Image: izsyo6.jpg]


Reply
#5
Aye, bad mistake. Confusing looking at code gray-gray.
Do what thou wilt shall be the whole of the Law. Love is the law, love under will.
.::The Rights of Man::.
Reply
#6
On windows you can use _getch(); for the "window not disappearing" effect.
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply
#7
Never knew those formulas to convert Thanks allot .
Reply
#8
Nice code bro Smile thanks tons
[Image: blanktemplate.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)