#include <iostream>
using namespace std;
const int ARRAY_SIZE = 10;
int test[ARRAY_SIZE] = {13579, 26791, 26792, 33445, 55555,62483,77777,79422,85647,93121};
//Prototype Functions.
int seqSearch(const int list[], int listLength,int searchItem);
int main()
{
//Declare variables.
int number;
int pos;
//declare input statement
cout<<'\n'<<endl;
cout <<'\t'<<'\t'<< "Please your ticket's number for this week: ";
cin >> number;
cout << endl;
//call search function.
pos = seqSearch(test, ARRAY_SIZE, number);
if (pos!= -1)
cout <<'\t'<<'\t'<<'\t'<<" Congratulations!!!"<<'\n'<<
'\t'<<'\t'<<"*** Your ticket number: " << number<< " is a winner this week *** " << endl;
else
cout << "Sorry!!!: " << number<< "but your ticket is not a winner this week." << endl;
system("pause");
return 0;
}
//Declare fuction for sequence search.
int seqSearch(const int list[], int listLength, int searchItem)
{
//declare variables.
int loc;
bool found = false;
loc = 0;
while (loc < listLength && !found)
if (list[loc] == searchItem)
found = true;
else
loc++;
if (found)
return loc;
else
return -1;
}
No comments:
Post a Comment