fork download
  1. //Cecilia Rangel CSC5 Chapter 8, P.487, #1
  2. //
  3. /**************************************************************
  4.  *
  5.  * COMPUTE WHETHER CHARGE
  6.  * ____________________________________________________________
  7.  * This program will prompt the user for a seven digit charge
  8.  * account number, if the number is in the array, it will be
  9.  * deemed valid, otherwise it will be deemed invalid.
  10.  *
  11.  *_____________________________________________________________
  12.  * INPUT
  13.  * accNum : a seven digit number from the user.
  14.  *
  15.  * OUTPUT
  16.  * message : comformation on wether or not the number
  17.  * entered is valid or not.
  18.  * ***************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22.  
  23. int main() {
  24. int validNum[18] = {5658845, 8080152, 1005231, 4520125, 4562555, 6545231,
  25. 7895122, 5552012, 3852085, 8777541, 5050552, 7576651,
  26. 8451277, 7825877, 7881200, 1302850, 1250255, 4581002};
  27. int accNum; //INPUT - seven digit number entered by user
  28. int count; //counter for element
  29. int position; //the position of the element in the array
  30. bool found; //flag to indicate whether value was found
  31. //
  32. //Prompt user to enter charge account number
  33. cout << "Enter your charge account number.\n";
  34. cin >> accNum;
  35. //
  36. //Loop linear search to find entered acoount number
  37. found = false;
  38. position = -1;
  39. for (count = 0; count < 18; count++)
  40. {
  41. if (accNum == validNum[count])
  42. {
  43. found = true;
  44. position = count;
  45. cout << "The number entered is valid.\n";
  46. }
  47.  
  48. }
  49. if (position == -1)
  50. cout << "The number entered is invalid.\n";
  51. return 0;
  52. }
Success #stdin #stdout 0s 5356KB
stdin
Standard input is empty
stdout
Enter your charge account number.
The number entered is invalid.