Question: I am posting only part of the c++ code because cheg wont allow all of it... Basically, I am able to get tm_hour to increase
I am posting only part of the c++ code because cheg wont allow all of it... Basically, I am able to get tm_hour to increase one time... BUT I want it to increase as many times as "menu 1" is chosen... Please point me in the right direction. See below:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int tm_hour;
int tm_min;
int tm_sec;
int twenty_four_hrs; // 12 hr clock conversion int
int menuFeature; // user's choice from menu
time_t now = time(0); // current date and time
tm* lt = localtime(&now);
tm_hour = twenty_four_hrs / 100; // convert from 24 hr to 12 hr formula
tm_min = twenty_four_hrs % 100;
tm_sec = twenty_four_hrs % 100;
// i left out menu choices 2,3, and 4
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 << "************************** **************************" << endl;
cout << "* 12-Hour Clock * * 24-Hour Clock *" << endl << endl;
cout << "* ";
// convert menu 1's 24 hr clock into 12 hr clock
if(lt -> tm_hour == 0 && lt -> tm_hour != 12)
{
lt -> tm_hour = 12;
printf("%.2d:%.2d:%.2d AM", lt -> tm_hour + 1, lt -> tm_min, lt -> tm_sec);
}
else if(lt -> tm_hour == 12 && lt -> tm_hour!= 0){
lt -> tm_hour = 12;
printf("%.2d:%.2d:%.2d PM",lt -> tm_hour + 1, lt -> tm_min, lt -> tm_sec);
}
else if(lt -> tm_hour < 12 && lt -> 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 + 1, lt -> tm_min, lt -> tm_sec);
}
else if(lt -> tm_hour > 12 && lt -> tm_hour != 0)
{
lt -> tm_hour = lt -> tm_hour - 12;
lt -> tm_min = lt -> tm_min;
lt -> tm_sec = lt -> tm_sec;
printf("%.2d:%.2d:%.2d PM", lt -> tm_hour + 1, lt -> tm_min, lt -> tm_sec);
// menu 1's conversion is complete
}
// menu 1: clocks' bottom (aesthetics)
cout << " * * ";
cout << lt -> tm_hour + 1 << ":" << lt -> tm_min << ":" << lt -> tm_sec << " *" << endl; // menu 1's 24 hr clock cout
cout << "************************** **************************" << endl << endl;
cin >> menuFeature; // get user's next menu choice
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
