From 5d832905197f850c64a4a659c4cdf7671880ba1c Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 19 Feb 2019 19:18:35 -0600 Subject: E --- ee1301/wk2/hw2_directory/strap012_2B.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'ee1301') diff --git a/ee1301/wk2/hw2_directory/strap012_2B.cpp b/ee1301/wk2/hw2_directory/strap012_2B.cpp index b5317bb..862a0de 100644 --- a/ee1301/wk2/hw2_directory/strap012_2B.cpp +++ b/ee1301/wk2/hw2_directory/strap012_2B.cpp @@ -21,28 +21,25 @@ int main() 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) { + + } + for (int i = hourChange; i >= 0; i--) { - if (i != 0) - { + if (i != 0) { intervalChange++; } - do - { - if (travel == 'B' && hourOG - intervalChange < 0) - { - if (hourChange < 12) - { + do { + if (travel == 'B' && hourOG - intervalChange < 0){ + if (hourChange < 12){ intervalChange -= 12; - } - else - { - intervalChange = 12 - intervalChange; - if (intervalChange >= 13) - { - intervalChange -= 12; + } else { + intervalChange = 12 - intervalChange; + if (intervalChange >= 13){ + intervalChange -= 12; + } } - } timeChange++; } } while (intervalChange > 12); -- cgit v1.2.3 From 1660be41ca5a4f9b083dcf220d018a610749fd11 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 19 Feb 2019 19:35:00 -0600 Subject: F --- ee1301/wk2/hw2_directory/strap012_2B.cpp | 67 ++++++++++---------------------- 1 file changed, 20 insertions(+), 47 deletions(-) (limited to 'ee1301') diff --git a/ee1301/wk2/hw2_directory/strap012_2B.cpp b/ee1301/wk2/hw2_directory/strap012_2B.cpp index 862a0de..be727a3 100644 --- a/ee1301/wk2/hw2_directory/strap012_2B.cpp +++ b/ee1301/wk2/hw2_directory/strap012_2B.cpp @@ -14,77 +14,50 @@ using namespace std; int main() { - bool change12 = 0, foo = 0; //Workaround to prevent unneeded if statements + 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; - if (hourOG+hourChange>12) { - - } - for (int i = hourChange; i >= 0; i--) { - if (i != 0) { - intervalChange++; - } - do { - if (travel == 'B' && hourOG - intervalChange < 0){ - if (hourChange < 12){ - intervalChange -= 12; + if (travel=='F') { + if (hourOG+hourChange>=12 && bar) { + if (hourOG+hourChange==12) { + timeChange++; } else { - intervalChange = 12 - intervalChange; - if (intervalChange >= 13){ - intervalChange -= 12; - } - } - timeChange++; + hourNew=(hourOG+hourChange)-12; + bar=false; + } } - } while (intervalChange > 12); - if (intervalChange >= 12) - { - //if (intervalChange !=12) {i - intervalChange = 0; - timeChange++; - //change12=1; } - } + if (travel=='B') { - /* if (hourOG+hourChange>=12 || hourOG-hourChange<=0) { - if (hourOG!=0 ^ hourOG!=12) { - hourOG-=12; } - if (hourChange>12) { - do { - hourChange-=12; - timeChange+=1; - } while (hourChange >=11); - } - change12=1; + if (intervalChange >= 12) { + intervalChange = 0; + timeChange++; + } } -*/ - for (timeChange; timeChange > 1; timeChange--) - { + for (timeChange; timeChange > 1; timeChange--) { //if (change12) { if (Time == 'A') { Time += 15; - foo = true; - } - if (Time == 'P' && !foo) - { + //foo = true; + } else { + if (Time == 'P') { //&& !foo) { Time -= 15; } - foo = 0; - //} + //foo = false; + } } - if (travel == 'F') { - hourNew = hourOG + intervalChange; + //hourNew = hourOG + intervalChange; } if (travel == 'B') { -- cgit v1.2.3