fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. constexpr double celsius_to_fahrenheit(double celsius)
  5. {
  6. return (celsius * 9.0) / 5.0 + 32.0;
  7. }
  8.  
  9. std::vector<double> get_input_celsius(std::size_t size)
  10. {
  11. std::vector<double> celsius(size);
  12. for (std::size_t i = 0; i != celsius.size(); ++i) {
  13. std::cout << "Celsius degree " << (i + 1) << ": ";
  14. std::cin >> celsius[i];
  15. }
  16. return celsius;
  17. }
  18.  
  19. void display_celsius_and_fahrenheit(std::vector<double> celsius)
  20. {
  21. std::cout << std::endl << "Celsius: " << "Fahrenheit:" << std::endl;
  22. for (auto c : celsius) {
  23. std::cout << c << " " << celsius_to_fahrenheit(c) << std::endl;
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. std::vector<double> celsius = get_input_celsius(3);
  30.  
  31. display_celsius_and_fahrenheit(celsius);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 3436KB
stdin
0 100 42
stdout
Celsius degree 1: Celsius degree 2: Celsius degree 3: 
Celsius:  Fahrenheit:
0         32
100         212
42         107.6