fork download
  1. //Xinnuo Wanng CS1A Chapter 8 #2 Page.487
  2. /*******************************************************************************
  3.  * Determine Winning number combination
  4.  * _____________________________________________________________________________
  5.  * The program initializes a vector and let the player to enter the winning
  6.  * number to check one of these number is winning.
  7.  * _____________________________________________________________________________
  8.  * Input
  9.  * win : The accepted winning number
  10.  *
  11.  * ****************************************************************************/
  12.  
  13. #include <iostream>
  14. #include <vector>
  15. using namespace std;
  16. int linear(vector<int> v,int size, int win);
  17. int main()
  18. {
  19. vector<int> arr = {
  20. 13579, 26791, 26792, 33445, 55555,
  21. 62483, 77777, 79422, 85647, 93121};
  22. int size = arr.size();
  23. int win;
  24. cout << "The winning number is: " ;
  25. cin >> win;
  26. cout << win<< endl;
  27. int m =linear(arr,size, win);
  28. if (m == -1)
  29. {
  30. cout << "None of them winning" << endl;
  31. }
  32. return 0;
  33. }
  34. int linear(vector<int> v, int size, int win)
  35. {
  36. bool found = false;
  37. int position = -1;
  38. int index =0;
  39. while (!found && index < size)
  40. {
  41. if (v[index] == win)
  42. {
  43. found = true;
  44. position = index;
  45. cout << "Congradulation!" << endl;
  46. }
  47. index++;
  48. }
  49. return position;
  50. }
Success #stdin #stdout 0.01s 5344KB
stdin
22222
stdout
The winning number is: 22222
None of them winning