Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++ ) Lottery Winners Modification Modify the program you wrote for Programming Challenge 2 (Lottery Winners) so it performs a binary search instead of a

(C++ )

Lottery Winners Modification Modify the program you wrote for Programming Challenge 2 (Lottery Winners) so it performs a binary search instead of a linear search.

this is my code:

#include

#include

using namespace std;

int main()

{

int winningDigits[6];

int player[6];

int digit, match = 0;

srand(time(NULL));

for (int i = 0; i < 6; i++)

{

winningDigits[i] = 0 + rand() % 9;

}

// Ask user to enter 6 digits

cout << "Enter your 6 lottery digits in the range of 0 to 9, "

<< "one number at a time. ";

for (int i = 0; i < 6; i++)

{

do

{

cout << "Number " << (i + 1) << ": ";

cin >> digit;

if (digit < 0 || digit > 9)

{

cout << "Invaild number "

<< "Pick a number in the range of 0 to 9. ";

}

} while (digit < 0 || digit > 9);

player[i] = digit;

}

for (int i = 0; i < 6; i++)

{

if (winningDigits[i] == player[i])

match++;

}

cout << "Winning digits : ";

for (int i = 0; i < 6; i++)

{

cout << winningDigits[i] << " ";

}

cout << endl;

cout << "player digits : ";

for (int i = 0; i < 6; i++)

{

cout << player[i] << " ";

}

cout << endl;

// Display number of matching digits

cout << "Matching digits: " << match << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

1. PricewaterhouseCoopers

Answered: 1 week ago

Question

3. SCC Soft Computer

Answered: 1 week ago