fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6.  
  7. int main()
  8. {
  9. double num = 0;
  10. double highest = 0;
  11. std::string unit = "";
  12. std::vector<double> v;
  13. std::cout << "Please, input number and a unit (m, cm, in, ft): ";
  14. while (std::cin >> num, std::cin >> unit)
  15. {
  16. std::cout << num << "\t" << unit << std::endl;
  17.  
  18. if (unit != "m" || unit != "cm" || unit != "in" || unit != "ft")
  19. {
  20. std::cout << "Please, input correct unit: m, cm, in, ft." << std::endl;
  21. break;
  22. }
  23.  
  24. if (unit == "m")
  25. {
  26. num = num * 100;
  27. }
  28. else if (unit == "in")
  29. {
  30. num = num * 2.54;
  31. }
  32. else if (unit == "ft")
  33. {
  34. num = num * 12 * 2.54;
  35. }
  36.  
  37. v.push_back(num);
  38.  
  39. sort(v.begin(), v.end());
  40. for (int i = 0; i < v.size(); i++)
  41. {
  42. highest = v[i];
  43. }
  44. std::cout << "The lowest number is: " << v[0] << std::endl
  45. << "The highest number is: " << highest << std::endl
  46. << "The vector size is: " << v.size() << std::endl;
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Please, input number and a unit (m, cm, in, ft):