fork download
  1. //Cameron Pham CS1A Chapter 8, p. 487, #1
  2. //
  3. /******************************************************************************
  4. * CHARGE ACCOUNT VALIDATION
  5. * ______________________________________________________________________________
  6. * This program accepts an integer value for an account number and determines
  7. * if the number is valid.
  8. * ______________________________________________________________________________
  9. * INPUT
  10. * Account number // Charge account number
  11. *
  12. * OUTPUT
  13. * Validation // Whether or not the account exists or not
  14. *******************************************************************************/
  15. #include <iostream>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. // Initialize Variables
  21. const int SIZE = 18;
  22. int accountNumbers[SIZE] =
  23. {
  24. 5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
  25. 8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
  26. 1005231, 6545231, 3852085, 7576651, 7881200, 4581002
  27. };
  28.  
  29. int accountNumber; // Account number entered by the user
  30. bool isValid = false; // Indicates whether the account is valid
  31.  
  32. // Ask the user to enter a charge account number
  33. cout << "Enter a charge account number: " << endl;
  34. cin >> accountNumber;
  35.  
  36. // Search the array for the account number
  37. for (int count = 0; count < SIZE; count++)
  38. {
  39. if (accountNumbers[count] == accountNumber)
  40. {
  41. isValid = true;
  42. break;
  43. }
  44. }
  45.  
  46. // Display whether the account number is valid
  47. if (isValid)
  48. {
  49. cout << "The account number is valid." << endl;
  50. }
  51. else
  52. {
  53. cout << "The account number is invalid." << endl;
  54. }
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5348KB
stdin
7895122
stdout
Enter a charge account number: The account number is valid.