//search list is sposed to work with pointer notation
//This program demonstrates a linear search to verify lottery numbers present or not present in a
//in ten tickets.
#include <iostream>
using namespace std;
//function prototypes
int main()
{
int searchList(int [], int, int);
const int SIZE = 10;
int results, value; //declare variables
int number[SIZE] = {13579, 26791, 26792, 33445, 55555,62483, 77777, 79422, 85647, 93121};
int *numPtr;
//declare fixed array of chosen tickets
numPtr = number;
cout << "The numbers in number array are:\n";
for (int index = 0; index < SIZE; index++)
{
cout << *numPtr << " ";
numPtr++;
}
cout << "Please enter the ticket number: " <<endl; //get user input
cin >> value;
results = searchList(number, SIZE, value); //perform search list
if (results == -1)
cout << "You did not win the lottery.\n"; //declare winner
else
{
cout << "You won the lottery";
cout << (results + 1) << ".\n";
}
return 0;
}
int searchList(int list[], int SIZE, int value) //declare function header
{
int *numPtr = list; //declare variables
int position = -1;
bool found = false;
while (numPtr <= &list[SIZE-1]) //establish while loop
{
if(*numPtr == value)
{
found = true;
position = *numPtr;
}
numPtr++;
}
return position;
}
This post has been edited by jimblumberg: 21 September 2012 - 05:48 AM
Reason for edit:: Took question out of the code tags.

New Topic/Question
Reply


MultiQuote





|