• Log in or sign up for an account here: https://www.sythe.org/login

Celsius and fahrenheit converter.

  • Thread starter Thread starter Ginsued
  • Start date Start date
G

Ginsued

Guest
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;
}
 
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.
 
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...

}
 
Runescape Gamblingrunescape gambling
Back
Top