From 986e3aa56c96097bb6993e48859ea6540e9ad7cc Mon Sep 17 00:00:00 2001 From: Michael Abed Date: Sun, 12 Feb 2012 15:20:36 -0500 Subject: Comment things and add headings --- Q2.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Q2.cpp') diff --git a/Q2.cpp b/Q2.cpp index 255b7f8..20e8d4a 100644 --- a/Q2.cpp +++ b/Q2.cpp @@ -1,3 +1,10 @@ +/* + * Michael Abed + * + * Lab 1 Problem 2 + * + * Convert units between pints, liters, and cups + */ #include @@ -5,6 +12,8 @@ using namespace std; int main() { + // the order here corresponds to the number that gets entered by the user + // it's just what needs to be multiplied by to get the corresonding unit double conversion[10] = {0.47317, 2, 0.5, 0.23659, 2.1134, 4.2268}; unsigned short sel; double amount; @@ -16,15 +25,15 @@ int main() cout << "Liters to Pints (enter 4)" << endl; cout << "Liters to Cups (enter 5)" << endl; - do { + do { // figure out operation cout << "?: "; cin >> sel; if (sel > 5) cout << "Enter a number between 0 and 5" << endl; } while (sel > 5); - do { - switch (sel) { + do { // validate input + switch (sel) { // decide how to prompt case 0: // fallthrough case 1: cout << "Enter the amount in Pints: "; @@ -44,7 +53,8 @@ int main() } while (amount < 0); double result = conversion[sel] * amount; - switch (sel) { + + switch (sel) { // show the output case 0: cout << amount << " Pints is " << result << " Liters" << endl; break; -- cgit v1.2.3