Question: C++ ... this program I wrote has two problems... the 12 hour clock goes 11:00, 12:00, 13:00, 2:00, 3:00, etc... I want it to say
C++ ... this program I wrote has two problems... the 12 hour clock goes 11:00, 12:00, 13:00, 2:00, 3:00, etc... I want it to say 1:00 not 13:00.... the second problem is that the 24 hour clock does not stop at 23:59. It will keep going: 24:00, 25:00, 26:00, 27:00, etc. --- the minutes and seconds are having the same issue. How can I fix it???










Hemin 000 1 #include // standard Library 2 #include // manipulate date and time information 3 #include /* dynamic memory management, random number generation, 4 communication with the environment, integer arithmetics, 5 searching, sorting and converting */ 6 #include // operate with physical devices such as keyboards, printers, terminals 7 #include // MS-DOS compilers to provide console input/output (Line 69 gelch) 8 using namespace std; // built in Library - commmon use stuff like: cout, cin, string, vector, map, etc. 9 10 int main() // entry point or start of the program 11 { 12 13 int tm_hour; // hours since midnight 14 int tm_min; // minutes after the hour 15 int tm_sec; // seconds after the minute 16 17 int menuFeature; // user's choice from menu 18 19 time t now = time(); // calls upon Library element time 20 tm* lt = localtime(&now); // holds the date and time in the form of a structure 21 22 // holds the original time in 24-hour format 23 tm_hour = lt -> tm_hour; // epoch translates into local time (hours) 24 tm_min = It -> tm_min; // epoch translates into local time (minutes) 25 tm_sec = lt -> tm_sec; // epoch translates into Local time (seconds) 26 // create clocks' top (aesthetics) cout tm_hour == 0 && lt -> tm_hour != 12) { lt -> tm_hour = 12; printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + AM } else if (lt -> tm_hour == 12 && lt -> tm_hour != 0) { lt -> tm_hour = 12; printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + PM else if (lt -> tm_hour tm_hour != 0) { lt -> tm_hour= lt -> tm_hour; lt -> tm_min= lt -> tm_min; lt -> tm_sec= lt -> tm_sec; printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + AM } else if (lt -> tm_hour > 12 && lt -> tm_hour != 0) { lt -> tm_hour - lt -> tm_hour - 12; It -> tm_min - lt -> tm_min; lt -> tm_sec = lt -> tm_sec; ************************** *************************** 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, It -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + PM // the created convertion is complete } // create clocks' bottom (aesthetics) cout > menuFeature; // get the user's first choice while(menuFeature != 4) // allow the user Limitless choices before ending program / menu 4 { == if (menuFeature { 1) // if user chooses menu 1 // menu 1: clocks' top aesthetics) cout tm_hour == 0 && lt -> tm_hour != 12) { lt -> tm_hour = 12; lt -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); } else if(lt -> tm_hour == 12 && lt -> tm_hour!= @){ lt -> tm_hour = 12; It -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); } 99 else if(lt -> tm_hour tm_hour != 0){ 100 lt -> tm_hour= lt -> tm_hour; 101 lt -> tm_min=lt -> tm_min; 102 lt -> tm_sec= lt -> tm_sec; 103 1t -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours 104 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, It -> tm_min, It -> tm_sec); 105 } 106 else if(lt -> tm_hour > 12 && lt -> tm_hour != 0) { 107 lt -> tm_hour It -> tm_hour 12; 108 It -> tm_min It -> tm_min; 109 It -> tm_sec = lt -> tm_sec; 110 It -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours 111 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 112 // menu I's conversion is complete 113 114 // menu 1: clocks' bottom (aesthetics) 115 cout > menuFeature; // get user's next menu choice * ******* *************** == ******** 123 124 125 } 126 127 128 else if (menuFeature 2) { // if user chooses menu 2 129 130 131 // menu 2: clocks' top (aesthetics) 132 cout tm_hour == 0 && lt -> tm_hour != 12 ){ 138 lt -> tm_hour 12; 139 It->tm_min It->tm_min + 1; // holds new time to increment minutes 140 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 141 142 else if(lt -> tm_hour == 12 && lt -> tm_hour!= 0) { 143 lt -> tm_hour = 12; 144 It->tm_min It->tm_min + 1; // holds new time to increment minutes 145 printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 146 } 147 else if(lt -> tm_hour tm_hour != 0) { 148 It -> tm_hour= lt -> tm_hour; 152 149 lt -> tm_min= lt -> tm_min; 150 lt -> tm_sec= lt -> tm_sec; 151 lt->tm_min It->tm_min + 1; // holds new time to increment minutes printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, It -> tm_sec); 153 } 154 else if(lt -> tm_hour > 12 && lt -> tm_hour != e) { 155 It -> tm_hour lt -> tm_hour 12; 156 lt -> tm_min It -> tm_min; 157 lt -> tm_sec - lt -> tm_sec; 158 It->tm_min 1t->tm_min + 1; // holds new time to increment minutes 159 printf("%.2d:%.2d:%.2d PM", It -> tm_hour, lt -> tm_min, lt -> tm_sec); 160 // menu 2's conversion is complete 161 162 // menu 2: clocks' bottom (aesthetics) 163 cout > menuFeature; // get user's next menu choice 171 172 173 } 174 ***** ***** ****** 175 176 else if (menuFeature == 3) { // if user chooses menu 3 177 178 179 // menu 3: clocks' top (aesthetics) 180 cout tm_hour == 0 && lt -> tm_hour != 12) { 186 It -> tm_hour 12; 187 lt->tm_sec = It->tm_sec + 1; // holds new time to increment seconds 188 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 189 } 190 else if(lt -> tm_hour == 12 && lt -> tm_hour!= 0) { 191 It -> tm_hour = 12; 192 1t->tm_sec It->tm_sec + 1; // holds new time to increment seconds 193 printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 194 } 195 y else if(lt -> tm_hour tm_hour != e) { 196 It -> tm_hour= lt -> tm_hour; 197 It -> tm_min= lt -> tm_min; 198 It -> tm_sec- lt -> tm_sec; 199 lt->tm_sec = It->tm_sec + 1; // holds new time to increment seconds 200 printf("%.2d:%.2d:%.20 AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 203 201 202 else if(lt -> tm_hour > 12 && lt -> tm_hour != e) { It -> tm_hour = lt -> tm_hour 12; 204 It -> tm_min = lt -> tm_min; 205 It -> tm_sec = lt -> tm_sec; 206 It->tm_sec = lt->tm_sec + 1; // holds new time to increment seconds 207 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 208 // menu 3's conversion is complete 209 } 210 211 // menu 3: clocks' bottom (aesthetics) 212 cout > menuFeature; // get user's next menu choice 220 221 222 } 223 224 225 else 226 ************ ***** 227 228 229 230 231 232 233 234 235 236 237 { // if user chooses menu 4 return; //break; } } } } Hemin 000 1 #include // standard Library 2 #include // manipulate date and time information 3 #include /* dynamic memory management, random number generation, 4 communication with the environment, integer arithmetics, 5 searching, sorting and converting */ 6 #include // operate with physical devices such as keyboards, printers, terminals 7 #include // MS-DOS compilers to provide console input/output (Line 69 gelch) 8 using namespace std; // built in Library - commmon use stuff like: cout, cin, string, vector, map, etc. 9 10 int main() // entry point or start of the program 11 { 12 13 int tm_hour; // hours since midnight 14 int tm_min; // minutes after the hour 15 int tm_sec; // seconds after the minute 16 17 int menuFeature; // user's choice from menu 18 19 time t now = time(); // calls upon Library element time 20 tm* lt = localtime(&now); // holds the date and time in the form of a structure 21 22 // holds the original time in 24-hour format 23 tm_hour = lt -> tm_hour; // epoch translates into local time (hours) 24 tm_min = It -> tm_min; // epoch translates into local time (minutes) 25 tm_sec = lt -> tm_sec; // epoch translates into Local time (seconds) 26 // create clocks' top (aesthetics) cout tm_hour == 0 && lt -> tm_hour != 12) { lt -> tm_hour = 12; printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + AM } else if (lt -> tm_hour == 12 && lt -> tm_hour != 0) { lt -> tm_hour = 12; printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + PM else if (lt -> tm_hour tm_hour != 0) { lt -> tm_hour= lt -> tm_hour; lt -> tm_min= lt -> tm_min; lt -> tm_sec= lt -> tm_sec; printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + AM } else if (lt -> tm_hour > 12 && lt -> tm_hour != 0) { lt -> tm_hour - lt -> tm_hour - 12; It -> tm_min - lt -> tm_min; lt -> tm_sec = lt -> tm_sec; ************************** *************************** 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, It -> tm_sec); // parse the string / format cout as 2 digit hour/min/sec + PM // the created convertion is complete } // create clocks' bottom (aesthetics) cout > menuFeature; // get the user's first choice while(menuFeature != 4) // allow the user Limitless choices before ending program / menu 4 { == if (menuFeature { 1) // if user chooses menu 1 // menu 1: clocks' top aesthetics) cout tm_hour == 0 && lt -> tm_hour != 12) { lt -> tm_hour = 12; lt -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); } else if(lt -> tm_hour == 12 && lt -> tm_hour!= @){ lt -> tm_hour = 12; It -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); } 99 else if(lt -> tm_hour tm_hour != 0){ 100 lt -> tm_hour= lt -> tm_hour; 101 lt -> tm_min=lt -> tm_min; 102 lt -> tm_sec= lt -> tm_sec; 103 1t -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours 104 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, It -> tm_min, It -> tm_sec); 105 } 106 else if(lt -> tm_hour > 12 && lt -> tm_hour != 0) { 107 lt -> tm_hour It -> tm_hour 12; 108 It -> tm_min It -> tm_min; 109 It -> tm_sec = lt -> tm_sec; 110 It -> tm_hour = lt -> tm_hour + 1; // holds new time to increment hours 111 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 112 // menu I's conversion is complete 113 114 // menu 1: clocks' bottom (aesthetics) 115 cout > menuFeature; // get user's next menu choice * ******* *************** == ******** 123 124 125 } 126 127 128 else if (menuFeature 2) { // if user chooses menu 2 129 130 131 // menu 2: clocks' top (aesthetics) 132 cout tm_hour == 0 && lt -> tm_hour != 12 ){ 138 lt -> tm_hour 12; 139 It->tm_min It->tm_min + 1; // holds new time to increment minutes 140 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 141 142 else if(lt -> tm_hour == 12 && lt -> tm_hour!= 0) { 143 lt -> tm_hour = 12; 144 It->tm_min It->tm_min + 1; // holds new time to increment minutes 145 printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 146 } 147 else if(lt -> tm_hour tm_hour != 0) { 148 It -> tm_hour= lt -> tm_hour; 152 149 lt -> tm_min= lt -> tm_min; 150 lt -> tm_sec= lt -> tm_sec; 151 lt->tm_min It->tm_min + 1; // holds new time to increment minutes printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, It -> tm_sec); 153 } 154 else if(lt -> tm_hour > 12 && lt -> tm_hour != e) { 155 It -> tm_hour lt -> tm_hour 12; 156 lt -> tm_min It -> tm_min; 157 lt -> tm_sec - lt -> tm_sec; 158 It->tm_min 1t->tm_min + 1; // holds new time to increment minutes 159 printf("%.2d:%.2d:%.2d PM", It -> tm_hour, lt -> tm_min, lt -> tm_sec); 160 // menu 2's conversion is complete 161 162 // menu 2: clocks' bottom (aesthetics) 163 cout > menuFeature; // get user's next menu choice 171 172 173 } 174 ***** ***** ****** 175 176 else if (menuFeature == 3) { // if user chooses menu 3 177 178 179 // menu 3: clocks' top (aesthetics) 180 cout tm_hour == 0 && lt -> tm_hour != 12) { 186 It -> tm_hour 12; 187 lt->tm_sec = It->tm_sec + 1; // holds new time to increment seconds 188 printf("%.2d:%.2d:%.2d AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 189 } 190 else if(lt -> tm_hour == 12 && lt -> tm_hour!= 0) { 191 It -> tm_hour = 12; 192 1t->tm_sec It->tm_sec + 1; // holds new time to increment seconds 193 printf("%.2d:%.2d:%.2d PM",lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 194 } 195 y else if(lt -> tm_hour tm_hour != e) { 196 It -> tm_hour= lt -> tm_hour; 197 It -> tm_min= lt -> tm_min; 198 It -> tm_sec- lt -> tm_sec; 199 lt->tm_sec = It->tm_sec + 1; // holds new time to increment seconds 200 printf("%.2d:%.2d:%.20 AM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 203 201 202 else if(lt -> tm_hour > 12 && lt -> tm_hour != e) { It -> tm_hour = lt -> tm_hour 12; 204 It -> tm_min = lt -> tm_min; 205 It -> tm_sec = lt -> tm_sec; 206 It->tm_sec = lt->tm_sec + 1; // holds new time to increment seconds 207 printf("%.2d:%.2d:%.2d PM", lt -> tm_hour, lt -> tm_min, lt -> tm_sec); 208 // menu 3's conversion is complete 209 } 210 211 // menu 3: clocks' bottom (aesthetics) 212 cout > menuFeature; // get user's next menu choice 220 221 222 } 223 224 225 else 226 ************ ***** 227 228 229 230 231 232 233 234 235 236 237 { // if user chooses menu 4 return; //break; } } } }