S
SneakyElf
I need to write a function where the third parameter points to an
address whose dereferenced value equals one of the array element's
value, then the the function returns the index of the first matching
array element. Otherwise -1 is returned.
Here's what I have but I am going obviously wrong somewhere:
#include <iostream>
using namespace std;
// This function compares values
void indexvalue (int array [], int size, int *num)
{
for (int count = 0; count < size; count++)
{
if (*num = array [count])
cout << count << endl;
else {
cout << "-1" << endl;
}
}
}
int main ()
{
int four = 4;
int arr [6] = {1, 2, 3,4,5};
int size = 6;
indexvalue (arr, size, &four);
return 0;
}
address whose dereferenced value equals one of the array element's
value, then the the function returns the index of the first matching
array element. Otherwise -1 is returned.
Here's what I have but I am going obviously wrong somewhere:
#include <iostream>
using namespace std;
// This function compares values
void indexvalue (int array [], int size, int *num)
{
for (int count = 0; count < size; count++)
{
if (*num = array [count])
cout << count << endl;
else {
cout << "-1" << endl;
}
}
}
int main ()
{
int four = 4;
int arr [6] = {1, 2, 3,4,5};
int size = 6;
indexvalue (arr, size, &four);
return 0;
}