fork download
  1. // Kurt Feiereisel CSC5 Chapter 8, p.487, #1
  2. /*******************************************************************************
  3.  *
  4.  * Validate Account Number
  5.  * _____________________________________________________________________________
  6.  * This program allows a user to enter a Charge Account number and the program
  7.  * will determine if the account number entered is valid or invalid.
  8.  * _____________________________________________________________________________
  9.  * INPUT:
  10.  * accNum : Account number of the user
  11.  *
  12.  * OUTPUT:
  13.  * Whether account number inputted is valid or invalid
  14.  *
  15.  *
  16.  * ****************************************************************************/
  17. #include <iostream>
  18. using namespace std;
  19.  
  20. // Function Prototypes
  21. int inputAccNum(int accNum);
  22. void determine(int validAccNums[], int accNum, int SIZE);
  23.  
  24. int main()
  25. {
  26. // Initailize Values
  27. int accNum = 0;
  28. int SIZE = 18;
  29.  
  30. // Array to hold Valid Account Numbers
  31. int validAccNums[SIZE] = {5658845, 4520125, 7895122, 8777541, 8451277,
  32. 1302850, 8080152, 4562555, 5552012, 5050552,
  33. 7825877, 1250255, 1005231, 6545231, 3852085,
  34. 7576651, 7881200, 4581002};
  35. // Call Functions
  36. accNum = inputAccNum(accNum); // Return value stored in accNum
  37. determine(validAccNums, accNum, SIZE); // Determine if accNum is Valid
  38. // or Invalid
  39. return 0;
  40. }
  41. /*******************************************************************************
  42.  * Definition of inputAccNum:
  43.  * This function allows a user to enter their charge account number. This
  44.  * function returns an int (num) back to main.
  45.  ******************************************************************************/
  46. int inputAccNum(int num)
  47. {
  48. // Input Account Number
  49. cout << "Please enter your Charge Account Number: " << endl;
  50. cin >> num;
  51.  
  52. // Return num to main
  53. return num;
  54. }
  55. /*******************************************************************************
  56.  * Definition of determine Function:
  57.  * This function determines if the account number entered is a valid
  58.  * account number.
  59.  ******************************************************************************/
  60. void determine(int valid[], int acc, int size)
  61. {
  62. // Initalize Local Variables
  63. int index = 0;
  64. int position = -1;
  65. bool found = false;
  66.  
  67. // Implement while loop to search for entered input value
  68. while (index < size && !found)
  69. {
  70. // If Account Number entered is equal to a stored account number
  71. if (valid[index] == acc)
  72. {
  73. found = true;
  74. position = index;
  75. }
  76. index++;
  77. }
  78.  
  79. // Display whether valid or invalid
  80. if(position != -1)
  81. cout << "Account Number Valid" << endl;
  82. else
  83. cout << "Account Number Invalid";
  84. }
  85.  
Success #stdin #stdout 0.01s 5304KB
stdin
9987565
stdout
Please enter your Charge Account Number: 
Account Number Invalid