homeworkhelp111

threshold

Feb 5th, 2022 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void GetUserValues(vector<int>& userValues, const int numValues) {
  7.     for (int i = 0; i < numValues; i++) {
  8.         cin >> userValues[i];
  9.     }
  10. }
  11. void IntsLessThanOrEqualToThreshold(vector<int> userValues, const int upperThreshold, vector<int>& resValues) {
  12.     int j = 0;
  13.     for (int i = 0; i < userValues.size(); i++) {
  14.         if (userValues[i] <= upperThreshold) {
  15.             resValues.push_back(userValues[i]);
  16.         }
  17.     }
  18. }
  19. int main() {
  20.     int size,i,threshold;
  21.     cin >> size;
  22.  
  23.     vector<int> userValues(size);
  24.     vector<int> resValues;
  25.  
  26.     GetUserValues(userValues, size);
  27.     cin >> threshold;
  28.  
  29.     IntsLessThanOrEqualToThreshold(userValues, threshold, resValues);
  30.  
  31.     for (i = 0; i < resValues.size(); i++) {
  32.         cout <<resValues[i] << " ";
  33.     }
  34.     cout<<endl;
  35.     return 0;
  36. }
Add Comment
Please, Sign In to add comment