fork download
  1. //Andrew Alspaugh CS1A Chapter 8. P. 487
  2. /****************************************************************************
  3. Validate Charge Accout Input
  4. _____________________________________________________________________________
  5. The purpose of this program is to validate an inputted account number
  6. ____________________________________________________________________________
  7. INPUT:
  8. SIZE: array size
  9. chargeNumber: array name
  10.  
  11. userInput: inputted account number
  12.  
  13. OUTPUT:
  14. valid: print true or false message
  15.  
  16. *******************************************************************************/
  17. #include <iostream>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. //DATA DICTIONARY
  23. const int SIZE = 18;
  24. long chargeNumber[SIZE] = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 8080152, 456255, 5552012, 505552, 7825877, 1250255, 1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
  25.  
  26. long userInput;
  27.  
  28. bool valid = false;
  29.  
  30. //INPUT
  31. cout << "Enter Charge Number" << endl;
  32. cin >> userInput;
  33.  
  34. //PROCESS
  35. for(int count = 0; count < SIZE; count++)
  36. {
  37. if (chargeNumber[count] == userInput)
  38. valid = true;
  39.  
  40. }
  41.  
  42. //OUTPUT
  43. if (valid == true)
  44. cout << "Number is Valid" << endl;
  45. if (valid == false)
  46. cout << "Number is Invalid" << endl;
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5308KB
stdin
5658845
stdout
Enter Charge Number
Number is Valid