[
//This program demonstrates a linerar search to verify lottery numbers present or not //present in ten tickets.
#include <iostream>
using namespace std;
//function prototypes
int searchList(int [], int, int);
const int SIZE = 10;
const int NUM_ROWS = 2;
const int NUM_COL = 5;
int main()
{
int results, value;
int number[SIZE] = {13579, 26791, 26792, 33445, 55555,62483, 77777, 79422, 85647, 93121};
//int number;
results = searchList(number, SIZE, 10);
cout << "Please enter the ticket number: " <<endl;
cin >> value;
if (results == -1)
cout << "You did not win the lottery.\n";
else
{
cout << "You won the lottery";
cout << (results + 1) << ".\n";
}
return 0;
}
int searchList(int list[], int size, int value)
{
int index = 0;
int position = -1;
bool found = false;
while (index < size && !found)
{
if(list[index] == value)
{
found = true;
position = index;
}
index++;
}
return position;
}
]
This post has been edited by GunnerInc: 12 September 2012 - 06:10 PM
Reason for edit:: added code tags

New Topic/Question
Reply



MultiQuote







|