Bool Find Price function help

This is a discussion on Bool Find Price function help within the C++ Programming forums, part of the General Programming Boards category; I need Help With this function I will attach the previous exercise to provide assistance all the arrays are defined ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    8

    Question 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.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    8
    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. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Ah yes...looks like another cross-poster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Restaurant Point-of-Sale Application: Help?!
    By matt.s in forum C Programming
    Replies: 14
    Last Post: 04-16-2010, 05:36 PM
  2. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 07:46 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21