Bool Find Price function help
I need Help With this function
I will attach the previous exercise to provide assistance
all the arrays are defined correctly i believe as it complies and outputs okay but it may need changes
For this function the requirements are as follows
We note that allTitles and allPrices are paired arrays. Hence if a book title is stored at for
instance position pos of the array allTitles, i.e. if the book title is represented by
allTitles[pos], then the corresponding book price would be stored at position pos of the array
allPrices, i.e. the corresponding book price would be stored as allPrices[pos]. You are
welcome to make use of the following structure if you don't wish to write your own completely.
Code:
bool findTitlePrice(string allTitles[], double allPrices[],
int totalRec, string title, double & price)
{
for(int i=0; i < totalRec; i++)
{
// your code here:
// for each element of array allTitles, check if it matches
// the given title, i.e. if title and allTitles[i] are the same;
// if yes, fetch the corresponding price from
// the array allPrices and exit the function (returned value: true)
}
// your code here:
I was Thinking that a cin of title checked against the first three values would be fine as there are only three values but a check on all elements would be a better solution the maxnumber of elements is 300
so a check on title which will pull in price then at the end return true or false
Would something like this work
cin << Title;
linearsearch ( Title <<allTitles []) maybe to check if the title is found then it could maybe grab the elment record and select from the allPrices array where element matches AllTitles elemnt ?
Would this work and how would the syntax be written.
Any Help on this would be greatly appreciated.