In the c++ functions when I tried to make a function in the program like this: float Pythagoras(int a, int b) It should work acccording to the page but this error appears: [Error] a function-definition is not allowed here before '{' token. Thank you.
{
float pyth;
pyth = (a*a + b*b);
pyth = pyth / pyth;
return pyth;
};
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.