Hi! I'm new to the forums and C++ in itself, but I am taking a class for it on the side and I just cannot seem to grasp this one linear search program. I feel like I am missing something basic but any help would be
greatly appreciated! Thanks all!
S0 here is the assignment:
Hardcode the following integer array: {7, 3, 32, 2, 55, 34, 6, 13,29,22, 11, 9, 1, 5,42,39, 8} into your program. Display this array to the user. Then ask the user to input an integer to search for. Your program should then search the array for the integer the user entered and output its array position (i.e., its array index). Your output should look similar to the following:
List = 7, 3, 32, 2, 55, 34, 6, 13, 29, 22, 11, 9, 1, 5, 42, 39, 8
Enter an integer in the list to search for: 55
Item found at index [4]
Press any key to continue
And here is what I have. As you can see, I cannot seem to figure out how to search for the integer or display it back to the user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
int value = 0;
int position = 0;
int array[17] = {7, 3, 32, 2, 55, 34, 6, 13, 29, 22, 11, 9, 1, 5, 42, 39, 8};
cout << "List = 7, 3, 32, 2, 55, 34, 6, 13, 29, 22, 11, 9, 1, 5, 42, 39, 8" << endl;
cout << "Enter an integer in the list to search for: ";
cin >> value;
}
|