A lottery ticket buyer purchases 10 tickets a week always pl
A lottery ticket buyer purchases 10 tickets a week, always playing the same 10 5-digit “lucky” combinations. Write a C++ program that initializes a vector with these numbers and then lets the player enter this week’s winning 5-digit number. The program should perform a linear 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
Solution
#include <iostream>
#include <vector>
using namespace std;
int main(){
//declaring variable for user\'s input for winningCombination
int winningCombination;
//initialising the luckyCombination vector with the given values
vector<int> luckyCombination;
luckyCombination.push_back(13579);
luckyCombination.push_back(26791);
luckyCombination.push_back(26792);
luckyCombination.push_back(33445);
luckyCombination.push_back(55555);
luckyCombination.push_back(62483);
luckyCombination.push_back(77777);
luckyCombination.push_back(79422);
luckyCombination.push_back(85647);
luckyCombination.push_back(93121);
//taking winnningCombination as input
cout<<\"Enter this week\'s wining 5-digit number: \";
cin>>winningCombination;
//linear search through the vector to find the winning combination
for (int i=0; i<luckyCombination.size(); i++){
if (luckyCombination[i] == winningCombination){
//reporting if winning combination found
cout<<\"Congratulations! You have the winning combination\"<<endl;
return 0; //terminating program if found
}
}
//reporting if winning combination not found
cout<<\"Sorry, you don\'t have the winning combination.\"<<endl;
return 0;
}
