fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. //Initialize Variables
  7. const int SIZE = 10; //Array Size
  8. int userNum; //User's Lottery Number
  9. int winOrLose = -1; //Lottery Result
  10. int luckyNums[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777,
  11. 79422, 85647, 93121};
  12.  
  13. //Ask For User Input
  14. cout << "Enter your lucky number: ";
  15. cin >> userNum;
  16. cout << userNum << endl;
  17.  
  18. //Linear Search
  19. for (int i = 0; i < SIZE; i++)
  20. {
  21. if (userNum == luckyNums[i])
  22. {
  23. winOrLose = i;
  24. break;
  25. }
  26. }
  27. if (winOrLose != -1)
  28. {
  29. cout << "Congratulations! You Won!" << endl;
  30. }
  31. else
  32. {
  33. cout << "Sorry. You did not win." << endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Enter your lucky number: 21923
Sorry. You did not win.