# Thread: Bool Find Price function help

1. ## 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++)
{
// 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)
}
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.

2. I have the following code so far

Code:
```# include <iostream>
# include <string>
# define MAXSIZE = 300
using namespace std;
bool findTitlePrice(string allTitles[MAXSIZE], double allPrices[MAXSIZE],
int totalRec, string title, double & price);

int main () ;
{

findTitlePrice(string allTitles[MAXSIZE], double allPrices[MAXSIZE], int totalRec, string title, double & price);

int totalRec =2;
for(int i=0;i<totalRec;i++);

string Title;
cin >> Title >>allTitles [MAXSIZE};{

if (Title == allTitles[MAXSIZE]);
cout << allprices [MAXSIZE];
return true;

else

return false;
}{
system ("pause");

}```

Now there are alot of errors in this program basically though i want to cin a value which is a string to match the alltitles array then check the value against the array if for example elemnt 3 in the allTitles array matches then cout element 3 in the all prices array

and return value true else if the cin title does not match anything return false

i know for sure the if title == statement does nothing just a placeholder for me so ignore this.

Any help on this would be greatly appreciated

any further questions feel free to post and i will accommodate you with answers if i can

3. Ah yes...looks like another cross-poster.