From 5244ec7aa2074cbbf450ba91e1fffa108ac11101 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 19 Feb 2019 21:13:02 +0000 Subject: (Screams internally) --- ee1301/wk2/hw2_directory/strap012_2B.cpp | 53 +++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'ee1301/wk2/hw2_directory') diff --git a/ee1301/wk2/hw2_directory/strap012_2B.cpp b/ee1301/wk2/hw2_directory/strap012_2B.cpp index e72b96d..b07028a 100644 --- a/ee1301/wk2/hw2_directory/strap012_2B.cpp +++ b/ee1301/wk2/hw2_directory/strap012_2B.cpp @@ -4,23 +4,42 @@ Name: Matthew Strapp Student ID number: 5449340 Course number: EE1301 Term: Spring 2019 -Lab/assignment number: Homework 2C -Short Program Description: Pay Stub Calculator +Lab/assignment number: Homework 2B +Short Program Description: Time Travel Calculator */ //15 #include using namespace std; int main () { - bool change12=0; //Workaround to prevent unneeded if statements - char Time, travel; //"time" is reserved - int hourOG, hourChange, hourNew, timeChange=0; + + bool change12=0, foo=0; //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; - - if (hourOG+hourChange>=12 || hourOG-hourChange<=0) { + for (int i=hourChange; i>=0; i--) { + if (i!=0){ + intervalChange++; + } do { + if (travel=='B' && hourOG-intervalChange<0){ + if (hourChange<12) + intervalChange=12-hourChange; + else + intervalChange=hourChange-12; + } + } while (intervalChange>12); + if (intervalChange>=12) { + //if (intervalChange !=12) {i + intervalChange=0; + timeChange++; + //change12=1; + } + } + +/* if (hourOG+hourChange>=12 || hourOG-hourChange<=0) { if (hourOG!=0 ^ hourOG!=12) { hourOG-=12; } @@ -32,23 +51,29 @@ int main () { } change12=1; } - for (timeChange; timeChange>0; timeChange--) { - if (change12) { +*/ + + for (timeChange; timeChange>1; timeChange--) { + //if (change12) { if (Time=='A') { Time+=15; + foo=true; } - if (Time=='P') { + if (Time=='P' && !foo) { Time-=15; } - } + foo=0; + //} } + if (travel=='F') { - hourNew=hourOG+hourChange; + hourNew=hourOG+intervalChange; } if (travel=='B'){ - hourNew=hourOG-hourChange; + hourNew=hourOG+intervalChange; } - + //Deprecated, doesn't work + //hourNew=hourOG+intervalChange; cout << "The new time is: " << hourNew << " " << Time << "M" << endl; return 0; -- cgit v1.2.3