// Kurt Feiereisel CSC5 Chapter 8, p.487, #2
/*******************************************************************************
*
* Determine if a User Won or Not
* _____________________________________________________________________________
* This program allows a user to enter this weeks winning lottery numbers. The
* function will then determine and report if the user won the lottery or not.
* _____________________________________________________________________________
* INPUT:
* winning : The winning lottery numbers for the week
* OUTPUT:
* Whether the user won the lottery or not
*
* ****************************************************************************/
#include <iostream>
using namespace std;
int inputWinningNum(int winning);
void determine(int purchased[], int winning, int SIZE);
int main()
{
// Initalize Variables
int winning = 0;
int SIZE = 18;
// Array to hold Purchased Ticket numbers
int purchased[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777,
79422, 85647, 93121};
// Call Functions
winning = inputWinningNum(winning);
determine(purchased, winning, SIZE);
return 0;
}
/*
* Definition of inputWinningNum:
* This function allows a user to enter the winning lottery numbers. This
* function will return the value entered to main.
*/
int inputWinningNum(int num)
{
// Input winning numbers
cout << "Please enter the winning lottery numbers: " << endl;
cin >> num;
return num;
}
/*
* Definition of determine Function:
* This function determines and reports whether the user won the lottery
*/
void determine(int tickets[], int win, int size)
{
// Initalize Local Variables
int index = 0;
int position = -1;
bool found = false;
// Search for matching values
while (index < size && !found)
{
if (tickets[index] == win)
{
found = true;
position = index;
}
index++;
}
// If matching number found display the user won
if(position != -1)
cout << "You Won!" << endl;
// If matching number was not found display user lost
else
cout << "You did not win.";
}