fork download
  1. //Ryan Robateau CSC5 Chapter 8. p. 487, #2
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Determine Winning Numbers
  6.  * _____________________________________________________________________________
  7.  * This program will prompt the user to enter 5 number for the lottery. The
  8.  * program will then call a function to verify of the numbers entered by the
  9.  * user are wining numbers. If the numbers are winning numbers then the program
  10.  * will then congradulate the user, if not then the program will tell the user
  11.  * that they go it wrong.
  12.  * _____________________________________________________________________________
  13.  ******************************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. using namespace std;
  17.  
  18. float numSearch(float lotteryNums[], int size, int user);
  19.  
  20. int main()
  21. {
  22. float userNums;
  23. int match;
  24. const int SIZE = 10;
  25. float luckNums[SIZE] = {13579, 26791, 26792,
  26. 33445, 55555, 62483,
  27. 77777, 79422, 85647,
  28. 93121};
  29.  
  30. cout << "Hello Welcome To The Lottery" << endl;
  31. cout << "Please Enter 5 Numbers: " << endl;
  32. cin >> userNums;
  33.  
  34. match = numSearch(luckNums, SIZE, userNums);
  35.  
  36. if( match == -1)
  37. {
  38. cout << "UNLUCKY!" << endl;
  39. cout << "Not Winning Numbers" << endl;
  40. }
  41. else
  42. {
  43. cout << "CONGRATS!" << endl;
  44. cout << "You Entered Winning Numbers" << endl;
  45.  
  46. }
  47.  
  48. return 0;
  49. }
  50.  
  51. float numSearch(float lotteryNums[], int size, int user)
  52. {
  53. int index = 0;
  54. int position = -1;
  55. bool found = false;
  56.  
  57. while(index < size && !found)
  58. {
  59. if(lotteryNums[index] == user)
  60. {
  61. found = true;
  62. position = index;
  63. }
  64. index++;
  65. }
  66. return position;
  67. }
Success #stdin #stdout 0s 5300KB
stdin
13579
stdout
Hello Welcome To The Lottery
Please Enter 5 Numbers: 
CONGRATS!
You Entered Winning Numbers