Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- double temp{0};
- string temp_unit;
- vector<double> numbers;
- double sum{0};
- constexpr double cm_to_m = 0.01;
- constexpr double ft_to_m = 0.3048;
- constexpr double in_to_m = 0.0254;
- cout<<"Enter an integer with its unit. E.g 2m or 2 m n";
- while(cin>>temp>>temp_unit){
- if(temp_unit=="m"){
- numbers.push_back(temp);
- }
- else if(temp_unit=="cm"){
- numbers.push_back(temp*cm_to_m);
- }
- else if(temp_unit=="ft"){
- numbers.push_back(temp*ft_to_m);
- }
- else if(temp_unit=="in"){
- numbers.push_back(temp*in_to_m);
- }
- else{
- cout<<"Incorrect Unitn";
- }
- }
- sort(numbers.begin(),numbers.end());
- for(auto& i:numbers){
- cout<<i<<" ";
- sum+=i;
- }
- cout<<"nNumber of elements "<<numbers.size()<<endl;
- cout<<"Sum of numbers: "<<sum<<endl;
- cout<<"Smallest number: "<<numbers[0]<<endl;
- cout<<"Largest number: "<<numbers[numbers.size()-1]<<endl;
- return 0;
- }
- double sum{0};
- double min{0};
- double max{std::numeric_limits<double>::infinity()};
- int count = 0;
- while(cin>>temp>>temp_unit){
- if(temp_unit=="m"){
- numbers.push_back(temp);
- }
- else if(temp_unit=="cm"){
- temp = (temp*cm_to_m);
- }
- else if(temp_unit=="ft"){
- temp = (temp*ft_to_m);
- }
- else if(temp_unit=="in"){
- temp = (temp*in_to_m);
- }
- else{
- cout<<"Incorrect Unitn";
- continue;
- }
- sum+=temp;
- if(min > temp) min = temp;
- if(max < temp) max = temp;
- count++;
- }
Add Comment
Please, Sign In to add comment