Code::Blocks Forums
User forums => Help => Topic started by: Karel Green on June 16, 2016, 08:18:05 pm
-
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;
}
-
PLEASE read the rules. http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)
And, remember C is a case sensitive language!
Tim S.
-
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;
}