Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include / / For setw and setfill using namespace std; / / Function to convert 2 4 - hour format to 1 2

#include
#include
#include // For setw and setfill
using namespace std;
// Function to convert 24-hour format to 12-hour format
void c12Hour(int hour24, int minute, int &hour12, string &period){
if (hour24==0){
hour12=12;
period ="AM";
} else if (hour24==12){
hour12=12;
period ="PM";
} else if (hour24>12){
hour12= hour24-12;
period ="PM";
} else {
hour12= hour24;
period ="AM";
}
}
int main(string){
int hour24, minute;
int hour12,answer,y,Y;
char colon;
string period;
cout << "Military Time Converter to Standard Time"<> hour24>> colon >> minute;
// Validate Input
c12Hour(hour24, minute, hour12, period);
do{
if (hour24>=0 && hour24<=11){cout << hour24<< colon << minute<<"="<11 && hour24<=23){
cout << hour24<< colon << minute<<"="<=24|| minute <0|| minute >=60){
cout <<"is not valid time" << endl;
}
else {
};
cout<< "Would you like to convert time? (y/n)"<< endl;
cin>> answer;
}
// Convert to 12-hour format
while (answer =='y'|| answer =='Y');
// Display the time in 12-hour format
return 0;
}
my code above is giving me this output. MilitaryTimeConvertertoStandardTime
InputMilitaryTime(hhmm):
14:25=02:25PM
Wouldyouliketoconverttime?(y/n)
what do i need to change to recieve
Expected Output
MilitaryTimeConvertertoStandardTime
InputMilitaryTimehh:mm
14:25=2:25PM
Wouldyouliketoconvertanothertime(y/n)
00:15=12:15AM
Wouldyouliketoconvertanothertime(y/n)
12:15=12:15PM
Wouldyouliketoconvertanothertime(y/n)
12:69isnotavalidtime
Wouldyouliketoconvertanothertime(y/n)
25:25isnotavalidtime
Wouldyouliketoconvertanothertime(y/n)

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 Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions