I'm having a hard time writing the body of the bolded functions. Any help would be great.
#include <iostream>
#include <ctime>
using namespace std;
bool findIt(int* start, int* end, int value);
//this function will search the array beginning with start
//and ending with end for the presence of value
//if found it returns true, if not return false
void randomizeIt(int* start, int length, int max);
// this function will fill the array starting at start
//with random numbers between 1 and max until it reaches length
int main()
{
//define variables
bool again = true; // controls whether user wants to find
//another number
const int MaxSize = 10; // number of items in the array
const int MaxNum = 100; // max value of item in array
int numArray[MaxSize -1];
int userInput = -1; //value entered by user to search for
srand(time(0));
do{
if (userInput == -1) //randomize array - if userInput = -1
randomizeIt(numArray, MaxSize, MaxNum);
cout << "Enter a number between 1 and " << MaxNum <<
" (0 = quit, -1 = randomize array ";
cin >> userInput;
if (userInput > 0){
if(findIt(numArray, &numArray[MaxSize-1], userInput))
cout << "found " << userInput <<endl;
else cout << userInput << " not found" << endl;
}else{
if(userInput != -1) again = false;
}
}while (again);
return 0;
}
bool findIt(int* start, int* end, int value)
{
for (int *p = start; p<=end; p++) {
if (*p == value)
return true;
}
return false;
}
#include <stdlib.h>
void randomizeIt(int* start, int length, int max)
{
for (int *p = start; p<=end; p++) {
*p = rand() % max; // could also use "random()"
}
}