User forums > Help
Can somebody help me with my code
(1/1)
Karel Green:
I'm trying to make a simple Fahrenheit to Celsius converter using functions but my code keeps giving me an error saying th function was not declared within the scope. Here is my code, any help would be great:
#include <iostream>
using namespace std;
fToC(float degreesF){
float degreesC = ((5.0/9.0)*(degreesF-32.0));
return degreesC;
}
int main(){
float fahrenheit;
float centigrade;
cout << "Enter a Fahrenheit temperature:" << endl;
cin >> fahrenheit;
centigrade = ftoC(fahrenheit); //This is the line where the compiler indicates an error.
cout << fahrenheit << "F is " << centigrade << "C";
return 0;
}
stahta01:
PLEASE read the rules. http://forums.codeblocks.org/index.php/topic,9996.0.html
And, remember C is a case sensitive language!
Tim S.
flymoon87:
You missed "float" when you declared fToC(float degreesF), and it should be f"T"oC not f"t"oC when you invoked it.
#include <iostream>
using namespace std;
//float is missed below
float fToC(float degreesF){
float degreesC = ((5.0/9.0)*(degreesF-32.0));
return degreesC;
}
int main(){
float fahrenheit;
float centigrade;
cout << "Enter a Fahrenheit temperature:" << endl;
cin >> fahrenheit;
centigrade = fToC(fahrenheit); //should be "T" here, not "t"
cout << fahrenheit << "F is " << centigrade << "C";
return 0;
}
Navigation
[0] Message Index
Go to full version