logo codesdope

Help with the c++ functions.

   Simply Xtra , International School @ Park City

In the c++ functions when I tried to make a function in the program like this:

    float Pythagoras(int a, int b)
    {
        float pyth;
        pyth = (a*a + b*b);
        pyth = pyth / pyth;
        return pyth;
    };

It should work acccording to the page but this error appears:

[Error] a function-definition is not allowed here before '{' token.

Thank you.


Answers

  •    Aakhya Singh

    I checked and it works fine for the following program.

    #include <iostream>
    using namespace std;
    float Pythagoras(int a, int b)
        {
            float pyth;
            pyth = (a*a + b*b);
            pyth = pyth / pyth;
            return pyth;
        };
    int main() {
    	std::cout << Pythagoras(3,4);
    	return 0;
    }
    

    Can you post your entire code. There can be different reasons why you might be getting this error like defining the function inside the main function.



Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.