The lottery winner A lottery ticket buyer purchases 10 tickets a week, always pl
ID: 3658363 • Letter: T
Question
The lottery winner
A lottery ticket buyer purchases 10 tickets a week, always playing the same 10 5 digit "lucky" combinations. Write a program that initializes an array or a vector with these numbers and then lets the player enter this weeks winning 5 digit number. The program should perform a linear search through the list of the players numbers and report whether or not one of the tickets is a winner this week. Here are the numbers:
13579 26791 26762 33445 55555 62483 77777 79422 85647 93121
Here is my code :
#include <iostream>
using namespace std;
int main()
{
int numbers[10]={13579,26791,26792,33445,55555,
62483,77777,79422,85647,93121};
int i,win=-1, n;
cout<<"Enter the winning number: ";
cin>>n;
for(i=0;i<10;i++)
if(n==numbers[i])
{
cout << n <<" is a winner!!! :) ";
win=i;
}
if(win<0)
cout<<"Sorry you did not win ";
return 0;
}
I have to do both of an array and vector style.
Please help me to do both of them base on my code.
Do it as simple as you can which I can understand it.
Thanks
Explanation / Answer
// using arrays int main(){ int a[10] = {13579,26791,26792,33445,55555, 62483,77777,79422,85647,93121}; int n; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.