Close
Close

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.

  • it's absolutely correct but you have to write function definition as a separate piece of code outside any other function call or definition.
    - mittal_akarsh

Answers

  •   

    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.



Ask Yours
Post Yours
Write your answer