News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Can somebody help me with my code

Started by Karel Green, June 16, 2016, 08:18:05 PM

Previous topic - Next topic

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

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

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;
}