In file included fromusrincludec48cassert430 from ex2cpp2 ex
In file included from/usr/include/c++/4.8/cassert:43:0, from ex2.cpp:2; ex2.cpp: In function \'int main()\'; ex2.cpp:19:29: error: invalid conversion from \'int\' to \'int\' [-fpermissive] assert(count0occurences(k)); ex2.cpp:19:29: error: too few arguments to function \'int countOccurences(int*, int, int)\' ex2.cpp:6:5: note: declared here int countOccurences (int a[], int len, int k) In file included from/user/include/c++/4.8/cassert:43:0; from ex2.cpp:2: ex2.cpp:19:5: error: expression cannot be used as a function assert (countOccurences(k)); dengineer:tilde/workspace/arrays s #include #include using namespace std; int countOccurences (int int len, int k) {int I = 0, count = 0; for (i = 0; i
Solution
The error is you aren\'t passing valid parameters to countOccurences function.
Placed the working code below
#include <iostream>
#include <cassert>
using namespace std;
int countOccurences(int a[],int len,int k)
{
int i=0,count=0;
for(i=0;i<len;i++)
if(a[i]==k)
count++;
return count;
}
int main(){
int a[]={1,2,3,4,3,2,1};
int k=3;
assert(countOccurences(a,7,k));
return 0;
cout<<\"All tests passed.\"<<endl;
}
