fork download
  1. // Kurt Feiereisel CSC5 Chapter 8, p.487, #2
  2. /*******************************************************************************
  3.  *
  4.  * Determine if a User Won or Not
  5.  * _____________________________________________________________________________
  6.  * This program allows a user to enter this weeks winning lottery numbers. The
  7.  * function will then determine and report if the user won the lottery or not.
  8.  * _____________________________________________________________________________
  9.  * INPUT:
  10.  * winning : The winning lottery numbers for the week
  11.  * OUTPUT:
  12.  * Whether the user won the lottery or not
  13.  *
  14.  * ****************************************************************************/
  15. #include <iostream>
  16. using namespace std;
  17. int inputWinningNum(int winning);
  18. void determine(int purchased[], int winning, int SIZE);
  19.  
  20. int main()
  21. {
  22. // Initalize Variables
  23. int winning = 0;
  24. int SIZE = 18;
  25.  
  26. // Array to hold Purchased Ticket numbers
  27. int purchased[SIZE] = {13579, 26791, 26792, 33445, 55555, 62483, 77777,
  28. 79422, 85647, 93121};
  29.  
  30. // Call Functions
  31. winning = inputWinningNum(winning);
  32. determine(purchased, winning, SIZE);
  33. return 0;
  34. }
  35. /*
  36.  * Definition of inputWinningNum:
  37.  * This function allows a user to enter the winning lottery numbers. This
  38.  * function will return the value entered to main.
  39.  */
  40. int inputWinningNum(int num)
  41. {
  42. // Input winning numbers
  43. cout << "Please enter the winning lottery numbers: " << endl;
  44. cin >> num;
  45. return num;
  46. }
  47. /*
  48.  * Definition of determine Function:
  49.  * This function determines and reports whether the user won the lottery
  50.  */
  51. void determine(int tickets[], int win, int size)
  52. {
  53. // Initalize Local Variables
  54. int index = 0;
  55. int position = -1;
  56. bool found = false;
  57.  
  58. // Search for matching values
  59. while (index < size && !found)
  60. {
  61. if (tickets[index] == win)
  62. {
  63. found = true;
  64. position = index;
  65. }
  66. index++;
  67. }
  68.  
  69. // If matching number found display the user won
  70. if(position != -1)
  71. cout << "You Won!" << endl;
  72.  
  73. // If matching number was not found display user lost
  74. else
  75. cout << "You did not win.";
  76. }
  77.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty