-
Fahenhieght?
I'm makeing a converter, but it wont compile
Code:
#include <iostream>
int far ( int x )
{
return (x-32)*(5/9);
}
int cel ( int x )
{
return x+32*(9/5);
}
using namespace std;
int faren();
int cels();
int main ()
{
int input;
cout<<"1. Celsius to Fahrenheit\n";
cout<<"2. Fahrenheit to Celsius\n";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1:
cels();
break;
case 2:
faren();
break;
default:
cout<<"Error\n";
break;
}
int faren {
int x;
cout << "Temperature Farenhieht:";
cin>> x;
cin.ignore();
cout << "Celsius:" << far(x);
cin.get();
}
int cels(){
int x;
cout << "Temperature Celsius:";
cin>> x;
cin.ignore();
cout << "Fahrenheit:" << cel (x);
cin.get();
}
Someone tell me what's wrong!
-
-
You forgot to close int main()
}
-
Clear result of the weird indentation. Always have opening and closing braces of blocks at the same indent level, unless the opening brace is at the end of a line. In that case, have the closing one at the level of that line.
-
And btw. to get from Celcius to Fahrenheit the algorithm is " Fahrenheit = ((Celcius*1.8)+32), that why 0 Celcius is 32 Fehrenheit.
If you have to get Celcius, just solve Celcius in the equation above. :)
-
The equations 5 / 9 which will always result in zero, and 9 / 5 will also produce undesirable results. The compiler identifies them as integers. Change them to floating point numbers 5.0 / 9.0 to get the proper results.
-
And close int main().. LOL
-
I got it!!!!!!!!!
Code:
#include <iostream>
float far ( float x )
{
return (x-32)*(5.0/9.0);
}
float cel ( float x )
{
return (x*1.8)+32;
}
using namespace std;
int faren();
int cels();
int main ()
{
int input;
cout<<"1. Celsius to Fahrenheit\n";
cout<<"2. Fahrenheit to Celsius\n";
cout<<"Selection: ";
cin>> input;
switch ( input ) {
case 1:
cels();
break;
case 2:
faren();
break;
default:
cout<<"Error\n";
break;
}
}
int faren() {
float x;
cout << "Temperature Farenhieht:";
cin >> x;
cin.ignore();
cout << "Celsius:" << far(x);
cin.get();
int input2;
cout<<"Start over 1.yes / 2.no :\n";
cin>> input2;
switch ( input2 ) {
case 1:
main();
break;
case 2:
cout:"/n";
break;
default:
cout<<"Error\n";
break;
}
}
int cels(){
float x;
cout << "Temperature Celsius:";
cin>> x;
cin.ignore();
cout << "Fahrenheit:" << cel (x);
cin.get();
int input3;
cout<<"Start over 1.yes / 2.no :\n";
cin>> input3;
switch ( input3 ) {
case 1:
main();
break;
case 2:
cout:"/n";
break;
default:
cout<<"Error\n";
break;
}
}
I know its a bit messy, but it works!
-
BTW, a big temperature converter is the only finished part of my tutorial. (Don't view with IE!)