fork download
  1. //Sam Trivikraman CS1A Chapter 8, p. 487, #1
  2. //
  3. /*
  4.  ******************************************************************************
  5. Validate Account Numbers
  6. _______________________________________________________________________________
  7. This program validates whether the number inputted is a valid account number.
  8. _______________________________________________________________________________
  9. INPUT
  10. the user's account number : The account number that the program is seraching for (user input)
  11.  
  12. OUTPUT
  13. valid/invalid : Whether or not the number that is inputted is in the array
  14. _______________________________________________________________________________
  15. *******************************************************************************
  16. */
  17. //
  18.  
  19.  
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main() {
  24.  
  25. int userAccNum; //INPUT the user's account number
  26. int SIZE = 18; //CONSTANT the size of the array
  27. //INPUT the array that contains all of the account numbers
  28. int accNumArray[SIZE] = {5658845, 4520125 , 7895122 , 8777541 , 8451277, 1302850, 8080152, 4562555, 5552012, 5050552, 7825877, 1250255, 1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
  29.  
  30. //Ask the user for the input (account number)
  31. cout << "Please enter the user number you are looking for." << endl;
  32. cin >> userAccNum;
  33.  
  34. //implement a linear search to look for the account number in the array
  35. //Output whether or not the number was valid
  36. for(int i = 0; i < SIZE; i++)
  37. {
  38. if(userAccNum == accNumArray[i])
  39. {
  40. cout << "This number is valid!" << endl;
  41. return 0;
  42. }
  43. else
  44. {
  45. cout << "This number is invalid." << endl;
  46. }
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5300KB
stdin
2
stdout
Please enter the user number you are looking for.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.
This number is invalid.