Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void printArray(int[5]);
  7. void userEnterArrayTwo(int[10]);
  8. bool checkUserEntry(int);
  9.  
  10. int main()
  11. {
  12.     //Variable Declaration Block
  13.    
  14.     int numArrayTwo[10];
  15.     int numArrayThree[10];
  16.  
  17.     //Algorithm Running
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.    
  25.     printArray(numArrayTwo);
  26.  
  27.    
  28.     userEnterArrayTwo(numArrayThree);
  29.    
  30.     printArray(numArrayTwo);
  31.     printArray(numArrayThree);
  32.  
  33.     system("pause");
  34.  
  35.     return 0;
  36. }
  37.  
  38.  
  39.  
  40. void printArray(int numArray[5])
  41. //This function prints all of the elements in the array.
  42. {
  43.     for (int i = 0; i < 10; i++)
  44.     {
  45.         cout << numArray[i] << " ";
  46.     }
  47.  
  48.     cout << endl;
  49. }
  50.  
  51.  
  52.  
  53. void userEnterArrayTwo(int numArray[10])
  54. //This function does error checking for the user and allows them to enter
  55. //all numbers into the array.
  56. {
  57.     int userEntry = 0;
  58.     int itr = 0;
  59.     bool entryGood = false;
  60.  
  61.     while (itr < 10)
  62.     {
  63.         cout << "Enter a number greater than -100 and less than 100:  ";
  64.         cin >> userEntry;
  65.  
  66.         entryGood = checkUserEntry(userEntry);
  67.  
  68.         if (entryGood)
  69.         {
  70.             cout << userEntry << " Entry valid!" << endl;
  71.             numArray[itr] = userEntry;
  72.             itr++;
  73.         }
  74.         else
  75.         {
  76.             cout << "Bad entry!  Please try again!" << endl;
  77.         }
  78.     }
  79.  
  80.     cout << "Array entry complete." << endl;
  81.  
  82. }
  83.  
  84. bool checkUserEntry(int entry)
  85. //Checks to make sure the variable is greater than 0 and returns a true/false
  86. //based on that.
  87. {
  88.     if (entry >= 0)
  89.     {
  90.         return true;
  91.     }
  92.     else
  93.     {
  94.         return false;
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement