Study results from Stroustrup's PPP3 book.

This commit is contained in:
Zed A. Shaw 2024-05-01 20:26:41 -04:00
parent 6363457d0f
commit 7a1093f982
10 changed files with 579 additions and 1 deletions

19
PPP3/ex02.cpp Normal file
View 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";
}
}