Question: (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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!