fork download
  1. //Jonathan Estrada CSC5 Chapter 8, P.487, #1
  2. /*******************************************************************************
  3.  * VALIDATE ACCOUNT NUMBER
  4.  * _____________________________________________________________________________
  5.  * This program will determine if the users account number is in the system or
  6.  * not. It will notify the user whether the number went through
  7.  * _____________________________________________________________________________
  8.  * INPUTS
  9.  * accountNumber : Account Numbers
  10.  * SIZE : array size
  11.  * userAccount : Users account number
  12.  *
  13.  * OUTPUT
  14.  * result : returning from the function positon
  15.  * *****************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int accountSearch( const int[], int, int);
  20. const int SIZE = 18;
  21.  
  22. int main() {
  23.  
  24. int accountNumber[SIZE] = {5658845, 4530125, 7895122, 8777541, 8451277,
  25. 1302850, 8080152, 4562555, 5552012, 5050552, 7825877, 1250255, 1005231,
  26. 6545231, 3852085, 7576651, 7881200, 4581002};
  27.  
  28. int userAccount;
  29. int result;
  30.  
  31. cout << "Please enter number associated with the account: ";
  32. cin >> userAccount;
  33. cout << userAccount << endl;
  34.  
  35. result = accountSearch(accountNumber, SIZE, userAccount);
  36.  
  37. if(result == -1)
  38. cout << "Account Number is not valid." << endl;
  39. else
  40. cout << "Account Number was found and valid." << endl;
  41.  
  42. return 0;
  43. }
  44. /*******************************************************************************
  45.  * Definition of function accountSearch.
  46.  * This function will determine if the users account number is valid returning
  47.  * its bool either true or false.
  48.  *
  49.  * *****************************************************************************/
  50. int accountSearch(const int accountSearch[], int SIZE, int userAccount)
  51. {
  52. int index = 0;
  53. int positon = -1;
  54. bool found = false;
  55.  
  56. while(index < SIZE && !found)
  57. {
  58. if(accountSearch[index] == userAccount)
  59. {
  60. found = true;
  61. positon = index;
  62. }
  63. index++;
  64. }
  65. return positon;
  66. }
Success #stdin #stdout 0.01s 5280KB
stdin
1232343
stdout
Please enter number associated with the account: 1232343
Account Number is not valid.