A lottery ticket buyer purchases ten tickets a week, always playing the same ten five-digit“lucky” combinations. Write a program that initializes an array with these numbers and then lets the player enter this week’s winning five-digit number. The program should perform a search through the list of the player’s numbers and report whether or not one of the tickets is a winner this week. Here are the numbers:

 

13579 26791 26792 33445 55555 62483 77777 79422 85647 93121

 

Print the total time it takes to run your program.

 

 

Solution

#include <iostream>

using namespace std;

 

int main() {

//clock starts

clock_t tStart = clock();

 

//array initialization

int combination[]         = {13579, 26791, 26792, 33445, 55555, 62483, 77777, 79422, 85647, 93121};

 

//input the winning number

int x;

cout << “Please enter this week’s five-digit number: “;

cin >> x;

 

//search through the array

for(int i = 0; i < 10; i++){

if(combination[i] == x){

cout << “Your number ” << combination[i] << ” is the winner!!” << endl;

break;

}

if(i==9){

cout << “You lose” << endl;

}

}

 

//print the run time

printf(“\nTime taken: %.5fs\n”, (float)(clock() – tStart)/CLOCKS_PER_SEC);

return 0;

}