This is a simple game I'm writing to test the idea of using games to teach C++. https://learncodethehardway.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

19 lines
522 B

#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";
}
}