C++ Need help urgent!

Im getting C++ forbids comparison between pointer and integer errors and a function-definition is not allowed here before ‘{’ token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#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'){
    	(getMenuChoice=='1');
    		cout<<factorial(getUserInput())<<endl;
    	(getMenuChoice=='2');
    		cout<<fibonacci(getUserInput())<<endl;
    printMenu();
    
   
    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 num;
	cout<<"Input a number 1-3"<<endl;
	cin>>num;
	if(num >='1') && (num  <='3')
		return num;
	
	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 num;
   cout<<"Input a number"<<endl;
   cin>>num;
   if (num >='0')
   	return num;
   
   cout<<"Invalid choice, please try again."<<endl;
   return getUserInput();
}
}
On line 26 and elsewhere, you are comparing a function name to a character. This tries to compare a pointer to the function to a char, which is where the error is coming from. I imagine you meant to call the function.

On line 87 you need parentheses around the entire if condition.

In the future, you should post the entire error messages, including the line numbers and such.
Topic archived. No new replies allowed.