A function definition is not allowed here before {?


#include <iostream>
#include <cstdlib>
using namespace std;

// Prototypes
int fibonacci(int);
int factorial(int);
void printMenu();
int getMenuChoice();
int getUserInput();


/**
* This is the main function, where all of the functions will be called and the program
* will be controlled.
*/
int main(){

//YOUR CODE GOES HERE!
//Here your program will call functions in order to
//a. Print the menu
//b. Get the user's selection
//c. Based on that selection, do the proper function
//d. repeat from step a, unless they chose the 'Quit' option
printMenu();
while(getMenuChoice != 3){
if(getMenuChoice ==1);
cout<<factorial(getUserInput())<<endl;
if(getMenuChoice==2);
cout<<fibonacci(getUserInput())<<endl;
int getMenuChoice;
printMenu();

return 0;
return main;
}

/**
* This function will calculate the 'num' fibonacci number in a recursive fashion.
* Valid values for 'num' are num >= 0
* @param num is the fibonacci index desired
* @return The value of fibonacci(num)
*/
int fibonacci(int num){
//YOUR CODE GOES HERE
if(num==1)return 1;
if(num==0)return 0;

return num + sum(num-1)


}

/**
* This function will calculate the factorial of num in a recursive fashion
* Valid values for 'num' are num >= 0
* @param num is the number for which we are calculating the factorial
* @return will be num!
*/
int factorial(int num){
//YOUR CODE GOES HERE

if (num == 0 || num == 1)
return 1;
return num * factorial (num -1)
}

/**
* This function will print out the entire menu for this program
*/
void printMenu(){
cout<<"*******************************"<<endl;
cout<<"Please choose an option:"<<endl;
cout<<"1. Factorial(n)"<<endl;
cout<<"2. Fibonacci(n)"<<endl;
cout<<"3. Quit"<<endl;

}

/**
* This function will get the user's menu choice.
* It will continue to ask the user for a value until a valid value (1-3) is given.
* @return a valid menu choice from the user.
*/
int getMenuChoice(){
int n;
cout<<"Input a number 1-3"<<endl;
cin>>n;
if(n >='1') && (n <='3')
return n;
cout<<"Invalid choice, please try again."<<endl;


return getMenuChoice();
}


/**
* This function will ask the user for 'n', which will eventually be used in the
* calculation of fibonacci or factorial.
* @return a value for 'n' to be used in calculating fibonacci or factorial.
*/
int getUserInput(){
int n;
cout<<"Input a number"<<endl;
cin>>n;
if (n >='0')
return n;
cout<<"Invalid choice, please try again."<<endl;


return getUserInput();
}
}

Indent your code and you should see the problem much more easily.
Topic archived. No new replies allowed.