diff options
Diffstat (limited to 'ee1301')
-rw-r--r-- | ee1301/wk2/hw2_directory/strap012_2B.cpp | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/ee1301/wk2/hw2_directory/strap012_2B.cpp b/ee1301/wk2/hw2_directory/strap012_2B.cpp index 5adefd5..fb07e18 100644 --- a/ee1301/wk2/hw2_directory/strap012_2B.cpp +++ b/ee1301/wk2/hw2_directory/strap012_2B.cpp @@ -7,18 +7,77 @@ Term: Spring 2019 Lab/assignment number: Homework 2B Short Program Description: Time Travel Calculator */ -//15 + +//PROGRAMMER'S NOTE: This problem legitimately stumped me. I won't be suprised if this is where I lose most of my points for this assignment. #include <iostream> using namespace std; int main() { - bool change12=0, foo=0, bar=false; //Workaround to prevent unneeded if statements - char Time, travel; //"time" is reserved by C++, "Time" is not + bool change12 = 0, foo = 0, bar = true; //Workaround to prevent unneeded if statements + char Time, travel; //"time" is reserved by C++, "Time" is not int hourOG, hourChange, hourNew, intervalChange = 0, timeChange = 1; cout << "Enter current time (A for AM, P for PM): "; cin >> hourOG >> Time; cout << "How many hours forward or backward do you want to move the clock (F for forwards, B for backward): "; - cin >> hourChange >> travel; + cin >> travel >> hourChange; + for (int i = hourChange; i >= 0; i--) + { + if (i != 0) + { + intervalChange++; + } + + if (travel == 'F') + { + if (hourOG + hourChange >= 12 && bar) + { + if (hourOG + hourChange == 12) + { + timeChange++; + } + else + { + hourNew = (hourOG + hourChange) - 12; + bar = false; + } + } + } + + if (travel == 'B') + { + } + if (intervalChange >= 12) + { + intervalChange = 0; + timeChange++; + } + } + + for (timeChange; timeChange > 1; timeChange--) + { + if (Time == 'A') + { + Time += 15; + } + else + { + if (Time == 'P') + { + Time -= 15; + } + } + } + if (travel == 'F') + { + hourNew = hourOG + intervalChange; + } + if (travel == 'B') + { + hourNew = hourOG + intervalChange; + } + + cout << "The new time is: " << hourNew << " " << Time << "M" << endl; + return 0; }
\ No newline at end of file |