aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ee1301/wk2/hw2_directory/strap012_2B.cpp92
1 files changed, 52 insertions, 40 deletions
diff --git a/ee1301/wk2/hw2_directory/strap012_2B.cpp b/ee1301/wk2/hw2_directory/strap012_2B.cpp
index b35a9c9..b5317bb 100644
--- a/ee1301/wk2/hw2_directory/strap012_2B.cpp
+++ b/ee1301/wk2/hw2_directory/strap012_2B.cpp
@@ -11,42 +11,51 @@ Short Program Description: Time Travel Calculator
#include <iostream>
using namespace std;
-int main () {
+int main()
+{
- 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;
+ 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;
- for (int i=hourChange; i>=0; i--) {
- if (i!=0){
- intervalChange++;
- } do {
- // STILL BROKEN
- if (travel=='B' && hourOG-intervalChange<0){
- if (hourChange<12) {
- intervalChange=12-hourChange;
- } else {
- intervalChange=hourChange-12;
- if (intervalChange>=13) {
- intervalChange-=12;
+ for (int i = hourChange; i >= 0; i--)
+ {
+ if (i != 0)
+ {
+ intervalChange++;
+ }
+ do
+ {
+ if (travel == 'B' && hourOG - intervalChange < 0)
+ {
+ if (hourChange < 12)
+ {
+ intervalChange -= 12;
+ }
+ else
+ {
+ intervalChange = 12 - intervalChange;
+ if (intervalChange >= 13)
+ {
+ intervalChange -= 12;
+ }
}
+ timeChange++;
}
- timeChange++;
- }
- // STILL BROKEN
- } while (intervalChange>ear1ss2);
- if (intervalChange>=12) {
- //if (intervalChange !=12) {i
- intervalChange=0;
+ } while (intervalChange > 12);
+ if (intervalChange >= 12)
+ {
+ //if (intervalChange !=12) {i
+ intervalChange = 0;
timeChange++;
//change12=1;
}
}
-/* if (hourOG+hourChange>=12 || hourOG-hourChange<=0) {
+ /* if (hourOG+hourChange>=12 || hourOG-hourChange<=0) {
if (hourOG!=0 ^ hourOG!=12) {
hourOG-=12;
}
@@ -60,29 +69,32 @@ int main () {
}
*/
- for (timeChange; timeChange>1; timeChange--) {
+ for (timeChange; timeChange > 1; timeChange--)
+ {
//if (change12) {
- if (Time=='A') {
- Time+=15;
- foo=true;
- }
- if (Time=='P' && !foo) {
- Time-=15;
- }
- foo=0;
+ if (Time == 'A')
+ {
+ Time += 15;
+ foo = true;
+ }
+ if (Time == 'P' && !foo)
+ {
+ Time -= 15;
+ }
+ foo = 0;
//}
}
- if (travel=='F') {
- hourNew=hourOG+intervalChange;
+ if (travel == 'F')
+ {
+ hourNew = hourOG + intervalChange;
}
- if (travel=='B'){
- hourNew=hourOG+intervalChange;
+ if (travel == 'B')
+ {
+ hourNew = hourOG + intervalChange;
}
//Deprecated, doesn't work
//hourNew=hourOG+intervalChange;
cout << "The new time is: " << hourNew << " " << Time << "M" << endl;
return 0;
-
-
-}
+} \ No newline at end of file