Study results from Stroustrup's PPP3 book.
This commit is contained in:
parent
6363457d0f
commit
7a1093f982
10 changed files with 579 additions and 1 deletions
19
PPP3/ex02.cpp
Normal file
19
PPP3/ex02.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
constexpr double cm_per_inch = 2.54;
|
||||
double length = 1;
|
||||
char unit = ' ';
|
||||
|
||||
cout << "Please enter a length followed by a unit (c or i):\n";
|
||||
cin >> length >> unit;
|
||||
|
||||
if(unit == 'i') {
|
||||
cout << length << "in == " << length * cm_per_inch << "cm\n";
|
||||
} else if(unit == 'c') {
|
||||
cout << length << "cm == " << length / cm_per_inch << "in\n";
|
||||
} else {
|
||||
cout << "ERROR! " << unit << " is not a valid unit. Use i for inches or c for centimeters.\n";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue