summaryrefslogtreecommitdiff
path: root/Q2.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-02-12 15:20:36 -0500
committerMichael Abed <michaelabed@gmail.com>2012-02-12 15:20:36 -0500
commit986e3aa56c96097bb6993e48859ea6540e9ad7cc (patch)
tree9d406e9a2a90e3af396c31603c7fa38294628451 /Q2.cpp
parent0e81d872502c86f061cf9003b77ac5b0abdabcba (diff)
downloadec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.tar.gz
ec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.tar.bz2
ec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.zip
Comment things and add headings
Diffstat (limited to 'Q2.cpp')
-rw-r--r--Q2.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/Q2.cpp b/Q2.cpp
index 255b7f8..20e8d4a 100644
--- a/Q2.cpp
+++ b/Q2.cpp
@@ -1,3 +1,10 @@
+/*
+ * Michael Abed <mgabed@bu.edu>
+ *
+ * Lab 1 Problem 2
+ *
+ * Convert units between pints, liters, and cups
+ */
#include <iostream>
@@ -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;