I an trying to do an assignment to run a recursive algorithm:
#include <iostream>
using namespace std;
float fact (float n);
int main () {
float n,r;
cout <<"Calculates factorial, whole number: "<< endl;
cin >> n;
r = fact(n);
cout <<"El resultado es: "<< r << endl;
return 0;
}
The problem is I am getting this error an i dont know how to fix it!
Undefined symbols for architecture x86_64:
"fact(float)", referenced from:
_main in ExtraCredit1-b26fe0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Do you guys have any ideas as to what it could be?
I made some changes to the code, but im still getting a few errors:
#include <iostream> // adds the reference to the input/output stream library
using namespace std; // the using directive
float fact (float n);
int main {
float n, r;
cout<<"Calcula Factorial, Entre Numeros: "<< endl;
cin >> n;
r = fact(n);
cout <<"El resultado es: "<< r << endl;
return 0;
}
ExtraCredit1.cpp:10:1: error: main cannot be declared as global variable
int main {;
^
ExtraCredit1.cpp:10:9: error: expected ';' after top level declarator
int main {;
^
;
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.