Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I know my switch is wrong but I can't figure out what I ' m supposed to use. Please check the rest of the code

I know my switch is wrong but I can't figure out what I'm supposed to use. Please check the rest of the code as well and see if I messed anything up or if you have any suggestions. I haven't been able to run the debugger yet so I'm not sure if I'm totally off on other things. Thank you!
#include
#include
#include
#include
using namespace std;
/*
This program will add one to each unit of time
*chosen by the user. Use a menu to pick the unit of time.
*Print out the clock in two formats, 12 and 24 hour.
*Author: Jordan Alarie
*Date: 7-20-24
*/
//Global variables
int hours;
int minutes;
int seconds;
//Gets the current time from the mother board
//Assigns it to hours, minutes, and seconds variables
void GetTime(){
time_t ttime = time(0); //Set ttime as argument for localtime function
tm* local_time = localtime(&ttime); //Holds the local time
//Assigns hours, minutes, and seconds from the local_time variable
hours = local_time->tm_hour;
minutes = local_time->tm_min;
seconds = local_time->tm_sec;
}
//Prints menu and asks for user choice
//Returns user choice
int menu(){
int choice;
//Display menu
cout << "Please make a section from the menu below." << endl;
cout << string(25,'*')<< endl;
cout <<"*1- Add One Hour \t\t*"<< endl;
cout <<"*2- Add One Minute \t\t*"<< endl;
cout <<"*3- Add One Second \t\t*"<< endl;
cout <<"*4- Exit \t\t\t*"<< endl;
cout << string(25,'*')<< endl;
//Get input
cin >> choice;
cout << "You selected: "<< choice << endl;
}
//Adds one unit to the hours
//Returns the updated time
void addHour(){
hours =(hours +1)%24;
}
//Adds one unit to the minutes
//Returns the updated time
void addMinute(){
minutes =(minutes +1)%60;
if (minutes ==0)
addHour();
}
//Adds one unit to the seconds
//Returns the updated time
void addSecond(){
seconds =(seconds +1)%60;
if (seconds ==0)
addMinute();
}
//Prints the 24 hour clock
//Parameter:hour min and sec
//Returns nothing
void print24(int hours, int minutes, int seconds){
cout << setw(2)<< setfill('0')<< hours <<':'
<< setw(2)<< setfill('0')<< minutes <<':'
<< setw(2)<< setfill('0')<< seconds;
}
//Prints the 12 hour clock
//Parameter:hour min and sec
//Returns nothing
void print12(int hours, int minutes, int seconds){
cout << setw(2)<< setfill('0')<< hours <<':'
<< setw(2)<< setfill('0')<< minutes <<':'
<< setw(2)<< setfill('0')<< seconds;
if (hours <12)
cout <<"AM";
else
cout <<"PM";
}
int main(){
int choice;
bool exitFlag = false;
while (!exitFlag){
//Gets the time from the motherboard
GetTime();
//Displays menu and takes choice
menu();
//Uses selection to add to requested time
switch (choice){
case 1:
print12.addHour();
print24.addHour();
case 2:
print12.addMinute();
print24.addMinute();
case 3:
print12.addSecond();
print24.addSecond();
case 4:
exitFlag = true;
break;
}
//Print clocks
print12();
print24();
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Assess three steps in the selection process.

Answered: 1 week ago

Question

Identify the steps in job analysis.

Answered: 1 week ago