Author Topic: Can somebody help me with my code  (Read 2639 times)

Karel Green

  • Guest
Can somebody help me with my code
« 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;
}


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7607
    • My Best Post
Re: Can somebody help me with my code
« Reply #1 on: June 16, 2016, 08:26:13 pm »
PLEASE read the rules. http://forums.codeblocks.org/index.php/topic,9996.0.html

And, remember C is a case sensitive language!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

flymoon87

  • Guest
Re: Can somebody help me with my code
« Reply #2 on: June 23, 2016, 03:40:54 pm »
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;
}