03-30-2010, 08:58 AM
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";
}
}