This is my first try at a method without input. Here is the code:
int factorial(int a) { int i = 1, result = 1; while (i <= a) { result = result * i; i++; } return result; } int double_factorial(int a) { int i = 2, result = 1; while (i <= a) { result = result * i; i = i + 2; } return result; } long double pi() { unsigned long int n = 4294967295; unsigned long int i = 0; long double result = 0; while (i <= n) { result = result + (factorial(i) / double_factorial(2 * i + 1)); i++; } long double pi = result * 2; return pi; } long double circumference_circle_input_radius(double r) { long double C = 2.0 * pi * r; //error: 'pi' expression must have arithmetic or unscoped enum type. } When I try to use method "pi" in this, the error appeared. I dont understand what the error means, so it is quite hard to understand the problem and debug it.
21 Answer
pi is a function, not a variable. To call it in an expression, you need to use parentheses:
long double C = 2.0 * pi() * r; ^^ Without the parentheses, the compiler thinks you're trying to multiply the function itself by 2, which isn't an operation that makes any sense.
0