Temperature Converter (Release)

This program can convert temperatures between the C,F,&K scales. After the conversion is made, it pauses, clears the screen, and then restarts main() for a new conversion.

Screenshot:
http://i.imgur.com/ZFwex.png

Raw code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int x;
	float temp;
	char z;
	
	cout << "\nWelcome to the Temperature Converter!\n\n";
	cout << "Please select a scale to convert from:\n1=Fahrenheit\t2=Celsius\t3=Kelvin\n";
	
	cin >> x;
		if( x==1 )
			{cout << "\nYou have selected Fahrenheit. Please enter a temperature:\n";
			cin >> temp;
			cout << "\n\n"<<temp<<" Fahrenheit is equal to:\n"<<(temp-32)*0.5555<<" Celsius\n"<<(0.5555*(temp-32))+273<<" Kelvin"<<endl<<endl;}
	
		else if( x==2 ){ 
			cout << "\nYou have selected Celsius. Please enter a temperature:\n";
			cin >> temp;
			cout << "\n\n"<<temp<<" Celsius is equal to:\n"<<(1.8*temp)+32<<" Fahrenheit\n"<<temp+273<<" Kelvin"<<endl<<endl;}
	
		else if( x==3 )
			{cout << "\nYou have selected Kelvin. Please enter a temperature:\n";
			cin >> temp;
			cout << "\n\n"<<temp<<" Kelvin is equal to:\n"<<((temp - 273) * 1.8 ) + 32<<" Fahrenheit\n"<<temp-273<<" Celsius"<<endl<<endl;}
	
		else if( x>3 )
			cout<< "\nInvalid selection entered\n\n";
	
		else if( x<1 )
			cout<< "\nInvalid selection entered\n\n";
	
	system("pause");
	system ("CLS");
	return main();
}
Last edited on
Nice job. Now put the menu in a loop and add an option to quit. Once you do that, why don't you try and take a string as input and detect what scale the user entered. For example, 32F would be Fahrenheit, 0C would be Celsius and 273K would be Kelvin, then just convert to the other scales that weren't entered. Also, try and not use system(), its slow, a security risk and most anti-virus products will flag your program as a virus.
Second the loop.

You're not allowed to call main. You need to put this in it's own function if you want to call it recursively.
Topic archived. No new replies allowed.