fork download
  1. //Ryan Robateau CSC5 Chapter 8, P. 487, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * DETERMINE ACCOUNT NUMBER VALIDITY
  6.  * _____________________________________________________________________________
  7.  * This program prompts the user to enter their account number
  8.  * and compares it to each of the values in the array to see if
  9.  * it is valid or not.
  10.  * _____________________________________________________________________________
  11.  ******************************************************************************/
  12. #include <iostream>
  13. using namespace std;
  14.  
  15. int searchlist(int accountnum[], int useraccountnum);
  16. const int SIZE = 18;
  17.  
  18. int main ()
  19. {
  20. int positionfound;
  21. int useraccountnum; // INPUT - User Account
  22. int accountnum[SIZE] = {5658845, 4520125, 7895122,
  23. 8777541, 8451277, 1302850,
  24. 8080152, 4562555, 5552012,
  25. 5050552, 7825877, 1250255,
  26. 1005231, 6545231, 3852085,
  27. 7576651, 7881200, 4581002};
  28. cout << "Enter Your Account Number: ";
  29. cin >> useraccountnum;
  30.  
  31. positionfound = searchlist(accountnum, useraccountnum);
  32. if (positionfound == -1)
  33. cout << endl << "Number invalid";
  34. else
  35. cout << endl << "Number Valid";
  36. return 0;
  37.  
  38. }
  39. int searchlist(int accountnum[], int useraccountnum)
  40. {
  41. int index = 0;
  42. int position = -1;
  43. bool found = false;
  44.  
  45. while (index < SIZE && !found)
  46. {
  47. if (accountnum[index]== useraccountnum)
  48. {
  49. found = true;
  50. position = index;
  51. }
  52. index++;
  53.  
  54. }
  55. return position;
  56.  
  57. }
Success #stdin #stdout 0.01s 5280KB
stdin
8080152
stdout
Enter Your Account Number: 
Number Valid