Guest User

Untitled

a guest
Nov 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 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. }
  46.  
  47. double sum{0};
  48. double min{0};
  49. double max{std::numeric_limits<double>::infinity()};
  50. int count = 0;
  51.  
  52. while(cin>>temp>>temp_unit){
  53. if(temp_unit=="m"){
  54. numbers.push_back(temp);
  55. }
  56. else if(temp_unit=="cm"){
  57. temp = (temp*cm_to_m);
  58. }
  59. else if(temp_unit=="ft"){
  60. temp = (temp*ft_to_m);
  61. }
  62. else if(temp_unit=="in"){
  63. temp = (temp*in_to_m);
  64. }
  65. else{
  66. cout<<"Incorrect Unitn";
  67. continue;
  68. }
  69. sum+=temp;
  70. if(min > temp) min = temp;
  71. if(max < temp) max = temp;
  72. count++;
  73. }
Add Comment
Please, Sign In to add comment