fork download
  1. //Diego Martinez CSC5 Chapter 8, P.487, #1
  2. /*******************************************************************************
  3. * DISPLAY CHARGE ACCOUNT VALIDATION
  4. * ______________________________________________________________________________
  5. * This program allows the user to enter a charge account number and checks
  6. * whether the number exists in a predefined list of valid account numbers using
  7. * a linear search. The program then displays a message indicating whether the
  8. * entered account number is valid or invalid.
  9. *
  10. * Computation is based on the Formula:
  11. * accounts[i] = accountNumber
  12. *______________________________________________________________________________
  13. * INPUT
  14. * accountNumber : Charge account number entered by the user
  15. *
  16. * OUTPUT
  17. * Message stating whether the account number is VALID or INVALID
  18. *******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. // Array of valid charge accounts
  25. int accounts[18] = {
  26. 5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
  27. 8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
  28. 1005231, 6545231, 3852085, 7576651, 7881200, 4581002
  29. };
  30.  
  31. int accountNumber;
  32. bool found = false;
  33.  
  34. //Ask user for account number
  35. cout << "Enter a charge account number: ";
  36. cin >> accountNumber;
  37.  
  38. // Linear search
  39. for (int i = 0; i < 18; i++)
  40. {
  41. if (accounts[i] == accountNumber)
  42. {
  43. found = true;
  44. }
  45. }
  46.  
  47. // Display result
  48. if (found)
  49. {
  50. cout << "The account number is VALID." << endl;
  51. }
  52. else {
  53. cout << "The account number is INVALID." << endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 5320KB
stdin
5658845
stdout
Enter a charge account number: The account number is VALID.