Advertisement
dabbill

Untitled

Oct 10th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. const size_t arraySize = 5;
  12. array< int, arraySize > duplicate = {};
  13.  
  14. for (int i = 0; i < arraySize; ++i)
  15. {
  16. int tempNumber;
  17. cout << "Enter a number between 10 and 100: ";
  18. cin >> tempNumber;
  19.  
  20. if (tempNumber <= 100 && tempNumber >= 10)
  21. {
  22.  
  23. bool dup = binary_search( duplicate.begin(), duplicate.end(), tempNumber);
  24. cout << "Number " << tempNumber << (dup ? " is a duplicate!" : " was stored in array." );
  25. (dup ? tempNumber : duplicate[i] = tempNumber);
  26. cout << endl;
  27. }
  28. else
  29. {
  30. cout << "Number is out of range!" << endl;
  31. }
  32. }
  33.  
  34. sort(duplicate.begin(), duplicate.end());
  35.  
  36. for( int x : duplicate)
  37. cout << x << " ";
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement