fork download
  1. // Timothy Price CS1A Ch 8 challenge 1
  2. /******************************************************************************
  3.  * Determine valid number
  4.  *
  5.  * This program receives a number and determines if it is valid or not.
  6.  *
  7.  * Input:
  8.  * Account number
  9.  *
  10.  * Output:
  11.  * Validity confirmation
  12.  *****************************************************************************/
  13.  
  14. #include <iostream>
  15. using namespace std;
  16.  
  17. const int SIZE = 18;
  18.  
  19. int main() {
  20. // data dictionary
  21. int valid_account[SIZE] = {
  22. 5658845, 4520125, 7895122, 8777541, 8451277, 8080152, 4562555, 5552012,
  23. 5050552, 7825877, 1005231, 6545231, 3852085, 7576651, 7881200, 1202850,
  24. 1250255, 4581002
  25. };
  26. int account;
  27. bool isValid = false;
  28.  
  29. // input account number
  30. cout << "Enter a charge account number: ";
  31. cin >> account;
  32. cout << account << endl;
  33.  
  34. // linear search loop
  35. for (int i = 0; i < SIZE; i++) {
  36. if (valid_account[i] == account) {
  37. isValid = true;
  38. break;
  39. }
  40. }
  41.  
  42. // display result
  43. if (isValid) {
  44. cout << "The account number is valid." << endl;
  45. }
  46. else {
  47. cout << "The account number is invalid." << endl;
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5348KB
stdin
4581005
stdout
Enter a charge account number: 4581005
The account number is invalid.