Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change this code to a binary search,last time you gave me the same code on binar

ID: 3629299 • Letter: C

Question

Change this code to a binary search,last time you gave me the same code on binary search c++ lottery program and I'm wasting pts cause the last code was mess up . I need a full code that can run, not a partial code a full code.




#include
using namespace std;

const int size=10;
int linearsearch(int array[], int size, int value)
{
for(int i=0; iif(array[i] == value) return 1;

}
int main()
{
int *numbers;
int N;
int count;
int results;
cout<<"How many lottery tickets were purchased?:";
cin>> N;
numbers= new int[N];
cout<<" Enter winning lottery ticket's numbers... ";
for (count=0; count{
cout<<"Winning Number Lottery ticket #"<<(count+1)<<": ";
cin>>numbers[count];
}

for (count=0; count{
cout<<" Enter your lottery number:";
cin>>results;

if (results == 0)
{
cout<<"Quitting Program ";
break;
}

int k=linearsearch(numbers,N,results);
if (k == 1)
cout<<"Winner! ";
else
cout<<"Loser! ";

}
return 0;
}

Explanation / Answer

please rate - thanks

not haveing the full question how's this

#include <iostream>
using namespace std;

const int size=10;
int binarysearch(int array[], int size, int value)
{int low=0,mid;
while(low<=size )
    {mid=(low+size)/2;
    if(array[mid]<value)
       low = mid + 1;
    else
        {if(array[mid]>value )
            size=mid-1;                  
        else
           return 1;
        }
     }
return 0;
}
int main()
{
int *numbers;
int N;
int count;
int results;
cout<<"How many lottery tickets were purchased?:";
cin>> N;
numbers= new int[N];
cout<<" Enter winning lottery ticket's numbers... ";
for (count=0; count<N;count++){
cout<<"Winning Number Lottery ticket #"<<(count+1)<<": ";
cin>>numbers[count];
}

cout<<" Enter your lottery number:";
cin>>results;

if (results == 0)
{
cout<<"Quitting Program ";
system("pause");
return 0;
}

int k=binarysearch(numbers,N,results);
if (k == 1)
cout<<"Winner! ";
else
cout<<"Loser! ";
system("pause");
return 0;


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote