So I'm writing a code for an introduction to programming with C++ course, and I can get the basis of the code written. However, I'm told to "implement a function search, which accepts an integer array of numbers, the array size and an integer value. The function returns true if the passed integer value is in the array and false". I honestly have no clue where to go, considering I've been trying to figure this out for days. Would an answer consist of a for loop? I'm so unsure.
Here's my code:
#include <iostream>
using namespace std;
bool search(int arr[], int size, int val);
const int SIZE = 25;
int main()
{
int nums[SIZE]; // Array Declaration
bool found;
int n;
// Initialize Array Nums
for (int i = 0; i < SIZE; i++)
{
nums[i] = rand() % 251;
}
// Display content of array nums
cout << "\n*******************\n";
for (int i = 0; i < SIZE; i++)
{
cout << nums[i] << "\t";
}
cout << "\n*******************\n";
cout << "Please enter a number between 0 to 250: " << endl;
cin >> n;
found = search(nums, SIZE, n);
if (found)
cout << n << " was found in our data set!\n";
else
cout << n << " was NOT found in our data set!\n";
return 0;
}