Advertisement
Spocoman

Metric Converter

Sep 20th, 2023
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     double number;
  8.     cin >> number;
  9.  
  10.     string inputMetric, outputMetric;
  11.     cin >> inputMetric >> outputMetric;
  12.  
  13.     if (inputMetric == "mm") {
  14.         if (outputMetric == "cm") {
  15.             number /= 10;
  16.         }
  17.         else {
  18.             number /= 1000;
  19.         }
  20.     }
  21.     else if (inputMetric == "cm") {
  22.         if (outputMetric == "m") {
  23.             number /= 100;
  24.         }
  25.         else {
  26.             number *= 10;
  27.         }
  28.     }
  29.     else {
  30.         if (outputMetric == "cm") {
  31.             number *= 100;
  32.         }
  33.         else {
  34.             number *= 1000;
  35.         }
  36.     }
  37.    
  38.     cout << fixed << setprecision(3) << number << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement