-
Notifications
You must be signed in to change notification settings - Fork 6
/
conversions.cpp
41 lines (39 loc) · 1.18 KB
/
conversions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
namespace mlb {
double inch2cm(double inches) {
if (inches < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return inches * 2.54;
}
double cm2inch(double centimeters) {
if (centimeters < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return centimeters * 0.393701;
}
double yard2cm(double yards) {
if (yards < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return yards * 91.44;
}
double cm2yard(double centimeters) {
if (centimeters < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return centimeters / 91.44;
}
double mile2km(double miles) {
if (miles < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return miles * 1.60934;
}
double km2mile(double kilometers) {
if (kilometers < 0) {
throw std::invalid_argument("Input value must be non-negative");
}
return kilometers / 1.60934;
}
}