Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Searching array (http://www.go4expert.com/forums/searching-array-t19371/)

Alex_code 10Sep2009 11:35

Searching array
 
Beginner *
new forum *

3 people (1 2 3) have reviewed books and each person has rated 5 books (10-50). The reviews are from 1 (bad) to 9 (great).

10 20 30 40 50 (# of book)
1 6 5 6 7 5
2 7 8 5 4 2
3 2 8 9 5 7

How do I create a program using a 2D array that lets the customer to enter values and then the code finds the answer that matches closest to input by the customer.

For example, if the user inputs a # of 6 for book 10 and 5 for book 50, then the closest match is choice 1.

Any tips/suggestions to get it started

aVague 11Sep2009 12:34

Re: Searching array
 
why the closest matc is choice 1 , isnt' it 3?
i don't get your point , explain more apropriate,please

xpi0t0s 12Sep2009 12:41

Re: Searching array
 
> Any tips/suggestions to get it started

Start with a main function, declare the array, create the input routine, then the search routine.
Do it a bit at a time and get each part working before you move onto the next bit (that's how I write programs).

You may like to skip the input routine and just use fixed values so that you can debug your search routine without having to re-enter the data every time.

For the search algorithm you may need to implement a number of checks. For example you would want to start with a check for an exact match (6 for 10 and 5 for 50 exactly matches 1). Then you might want to perform fuzzy checks where it looks for numbers that are close enough, but this risks returning multiple rows or surprising results. So if they enter 6 for 10 and 5 for 40 the closest match could be 1 because 6 matches exactly, or it could be row 2 because 5 is closer to 4 than to 7 (you would need to decide which constitutes a "closer" match). Or if they enter 8 for 20 and 7 for 30 then this is exactly half way between 2 and 3 and you might want to return both those results.


All times are GMT +5.5. The time now is 04:16.