Reply
Old 06-25-2014, 02:06 AM   #1 (permalink)
 
Status: Senior Member
Posts: 778



Default i cant get a number that's not in the array to trigger my cout statement that says its not in the array rather i left out the sort array

// This program performs a linear search on a number array


#include <iostream>
using namespace std;

int searchList( const int[], int, int); // function prototype
void selectionSort(int[], int); // function prototype
const int SIZE = 8;

int main()
{
int num[SIZE] = {3, 6, -19, 5, 5, 0, -2, 99};
int found;
int numb;


selectionSort (num, SIZE);//To sort the array because its a binary search


cout << "Enter a number to search for:" << endl;
cin >> numb;


found = searchList(num, SIZE, numb);

if (found == -1)
cout << "The number " << numb
<< " was not found in the list" << endl;
else




cout << "The number " << numb <<" is in the " << found
<< " position of the list" << endl;

return 0;

}


int searchList( const int num[], int SIZE, int numb)
{
int found = -1;
for (int count = 0; count <= SIZE; count++)
{
if (num[count] == numb)
{
found = count;
return found;
}
}
return found;
}
SweetHot is offline   Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Provided a 1D array of unsorted numbers, sort this array using the quicksort algorithm and return the sorted a? Trevor Coding 0 10-09-2013 10:07 PM
programming with C, array : write down the array elements value with their index number? MrPerfect Programming 1 07-12-2013 10:08 PM
counting with array. the number of times a word is used in another array? Austen Coding 0 03-04-2013 07:06 PM
Write a program which can take a name in a array as characters and sort an array? Unknown_User Programming 2 04-18-2012 10:38 AM
Java Arrays, adding to array, copy array, increasing length of array? MattL Coding 1 01-29-2012 07:08 AM