Help fixing invalid conversion error?

I'm still quite new to C++ and I am having trouble fixing an error in my program. Suggestions on how to fix it would be great. Thank you.
My compiler says: .cpp:13: error: invalid conversion from âint (*)()â to âintâ


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
#include <iostream>
using namespace std;

int getsearchValue ();
void displayResults (int s, int o);
int search (int arr[], int size, int s);

const int SIZE = 5;

int main () {

  int a[]= {10, 20, 40, 40, 50}, searchValue, occurs;
  searchValue = getsearchValue;
  occurs = search (a, SIZE, searchValue);
  displayResults (searchValue, occurs);
  return 0;
}
 
int getsearchValue () {
  int input;
  cout << "Enter searchValue: " ;
  cin >> input;
  return input;
}
  
void displayResults (int s, int o) {
  cout << s << "occurs" << o << "times/n";
}

int search (int arr[], int size, int s) {
  int count = 0;
  for (int i = 0; i < size && s >= arr[i]; i++)
    if (s == arr[i])
      count++;
}
Maybe instead of

searchValue = getsearchValue;

you meant

searchValue = getsearchValue();

?
Oh thank you! The answer was so simple! However, even though the compiler says I have no errors now. My program is not giving me the right output. For example, when I enter 40, it says it occurs 0 times, even though it is supposed to be 2.
maybe fix line 32 and make it something like
 
for (int i = 0; i < size; i++)
Last edited on
No, that still seems to give me the same result
1
2
3
4
5
6
7
int search (int arr[], int size, int s) {
  int count = 0;
  for (int i = 0; i < size && !( s < arr[i] ); i++)
    if (s == arr[i])  count++;

  return count;
}
Last edited on
Topic archived. No new replies allowed.