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 (program challenge 2) :

#include

using namespace std;

//Size as 7 const int size = 7;

//Winning Numbers int arrLottery[size]={13579, 26792, 55555, 62483, 79422, 85647, 93121};

//Linear Search int LinearSearch (int [], int, int);

int main()

{

int target, result;

//Take Inout from User cout<<"Please enter this week's 5-digit winning lottery number: ";

cin>>target;

//Call LinearSearch result = LinearSearch(arrLottery, size, target);

//Element found if (result != -1)

{

cout<<"you have a winning ticket."<

}

else

{ //Element NOT found cout<<"You did not win this week."<

}

cin.get(); cin.get();

return 0;

}

int LinearSearch (int arrLottery[], int Max, int target)

{

int index;

for (index = 0; index < Max-1; index++)

{

if (arrLottery[index] == target)

return 0;

}

return -1;

}

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!