fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool searchList(const int tickets[], int size, int winningNumber);
  5.  
  6. int main() {
  7. // array containing the player's 10 lucky numbers
  8. const int SIZE = 10;
  9. int playerTickets[SIZE] = {
  10. 13579, 26791, 26792, 33445, 55555,
  11. 62483, 77777, 79422, 85647, 93121
  12. };
  13.  
  14. int winningNumber = 0;
  15.  
  16. // Prompt the user to enter this week's winning combination
  17. cout << "Enter this week's winning 5-digit lottery number: ";
  18. cin >> winningNumber;
  19.  
  20. // Check if any of the player's tickets match the winning number
  21. if (searchList(playerTickets, SIZE, winningNumber)) {
  22. cout << "Congratulations! One of your tickets is a winner this week!" << endl;
  23. } else {
  24. cout << "Sorry, none of your tickets matched the winning number this week." << endl;
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30. // Function Definitions
  31.  
  32. // Performs a simple linear search to find the winning number in the player's ticket array
  33. bool searchList(const int tickets[], int size, int winningNumber) {
  34. for (int i = 0; i < size; i++) {
  35. if (tickets[i] == winningNumber) {
  36. return true; // Found a winning ticket
  37. }
  38. }
  39. return false; // No winning tickets found
  40. }
Success #stdin #stdout 0s 5344KB
stdin
Standard input is empty
stdout
Enter this week's winning 5-digit lottery number: Sorry, none of your tickets matched the winning number this week.