(Solved) : Lottery Ticket Buyer Purchases Ten Tickets Week Always Playing Ten Five Digit Lucky Combin Q29984905 . . .
A lottery ticket buyer purchases ten tickets a week, alwaysplaying the same ten five-digit “lucky” combinations. Write aprogram that initializes an array with these numbers and then letsthe player enter the week’s winning five-digit number. The programshould perform a linear search through the list of the player’snumbers and report whether or not one of the tickets is a winnerthis week. Here are the numbers:
13579 26791 26792 33445 55555
62483 77777 79422 85647 93121
Here is what I have so far. I’m making some sort of logicalerror that prevents me from outputting the correct answer at theend.
#include <iostream>
using namespace std;
int linearSearch(int array[], int size, int searchValue)
{
int result = -1;
for (int x=0; x < size; x++)
{
if (searchValue = array[x])
{
return x;
}
}
return result;
}
int main()
{
int numbers[10] = { 13579, 26791, 26792, 33445, 55555, 62483,77777, 79422, 85647, 93121 };
int value;
int userValue;
cout << “Enter a lottery number: ” << endl;
cin >> userValue;
value = linearSearch(numbers, 10, userValue);
if (value >= 0)
{
cout << “You have entered a winning number!” <<endl;
}
if (value < 0)
{
cout << “You have entered a losing number!” <<endl;
}
return 0;
}
Expert Answer
Answer to Lottery Ticket Buyer Purchases Ten Tickets Week Always Playing Ten Five Digit Lucky Combin Q29984905 . . .
OR