#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
usingnamespace std;
int numOccurences(int Array[],int sizeOfArray,int Value);
int main (void) {
int Value;
int sizeOfArray;
cout << " enter the size of your array and a value " ;
cin >> sizeOfArray >> Value;
int Array[sizeOfArray];
for (int i =0;i<sizeOfArray;i++){
cout << "Please enter a value ";
cin >> Array[i];
}
//why do i keep getting an error here
cout << "the number of times that value occured is " << numOccurences(Array[], sizeOfArray ,Value) << endl;
system("PAUSE"); return 0;
}
int numOccurences(int Array[],int sizeOfArray,int Value){
int count;
for (int i =0; i< sizeOfArray ;i++){
if (Array[i] = Value){
count++;
}
}
return count;
}
numOccurences(Array[], sizeOfArray ,Value)
is not how a function should take in an array parameter when being called.
Get rid of the [].
Other issues:
* Your compiler may not like that you are allocating a non-const int for the size of your array.
* in your numOccurences() function, you never initialize count to be 0 before you increment it.
* if (Array[i] = Value){ should be if (Array[i] == Value)
= is assignment operator.
== tests for equality.
Edit: Woops, sorry for saying what has already been said, the above posts didn't show up for me.