Guest User

Untitled

a guest
Nov 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double temp{0};
  9. string temp_unit;
  10. vector<double> numbers;
  11. double sum{0};
  12.  
  13. constexpr double cm_to_m = 0.01;
  14. constexpr double ft_to_m = 0.3048;
  15. constexpr double in_to_m = 0.0254;
  16.  
  17. cout<<"Enter an integer with its unit. E.g 2m or 2 m n";
  18. while(cin>>temp>>temp_unit){
  19. if(temp_unit=="m"){
  20. numbers.push_back(temp);
  21. }
  22. else if(temp_unit=="cm"){
  23. numbers.push_back(temp*cm_to_m);
  24. }
  25. else if(temp_unit=="ft"){
  26. numbers.push_back(temp*ft_to_m);
  27. }
  28. else if(temp_unit=="in"){
  29. numbers.push_back(temp*in_to_m);
  30. }
  31. else{
  32. cout<<"Incorrect Unitn";
  33. }
  34. }
  35. sort(numbers.begin(),numbers.end());
  36. for(auto& i:numbers){
  37. cout<<i<<" ";
  38. sum+=i;
  39. }
  40. cout<<"nNumber of elements "<<numbers.size()<<endl;
  41. cout<<"Sum of numbers: "<<sum<<endl;
  42. cout<<"Smallest number: "<<numbers[0]<<endl;
  43. cout<<"Largest number: "<<numbers[numbers.size()-1]<<endl;
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment