. Lottery Winners A lottery ticket buyer purchases 10 tickets a week, always pla
ID: 3629281 • Letter: #
Question
. Lottery WinnersA lottery ticket buyer purchases 10 tickets a week, always playing the same 10 5-digit “lucky” combinations. I need to write a program that initializes an array or a vector with these numbers and then lets the player enter this week’s winning 5-digit number. The program should perform a binary 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
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
int main()
{int numbers[10]={13579,26791,26792,33445,55555,
62483,77777,79422,85647,93121};
int low=0,max=10,mid;
int i,win=-1, n;
cout<<"Enter the winning number: ";
cin>>n;
while(low<=max )
{mid=(low+max)/2;
if(numbers[mid]<n)
low = mid + 1;
else
{if(numbers[mid]>n )
max=mid-1;
else
{cout<<n<<" is a winner!!! :) ";
low=15;
}
}
}
if(low!=15)
cout<<"Sorry you did not win ";
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.