Question

v +include <iostreams 2 #include <string> Instructions 3 Write a program to convert the time from 24-hour notation to 12-hourv Instructions Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program musv Instructions Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program musv Instructions } Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program mNeed some assistance of reorganizing this whole program. I have the right code for everything I just need help on putting all the codes in the right spot so it can come out to the correct output.

output is supposed to look like this:

1 \\ user inputs choice to convert 12 to 24

8 \\ user inputs 8 for hours

30 \\ user inputs 30 for minutes

20 \\ user inputs 20 for seconds

AM \\ user inputs AM for morning time

8:30:20 \\ then program displays the time converted

99 \\ user inputs 99 to exit the program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: For any issues or doubts, just put a comment before giving a thumbs down. Thanks.

COde( There were many faults in the logic so I fixed them ):

#include <iostream>
#include <string>

using namespace std;

void DisplayChoices();
void getTime12Format();
void getTime24Format();
void ConversionFrom12to24(int minutes, int hours, int seconds, string AMorPM);
void ConversionFrom24to12(int minutes, int hours, int seconds);
void Display12to24(int minutes, int hours, int seconds);
void Display24to12(int minutes, int hours, int seconds, string AMorPM);

int main(){

int input;
DisplayChoices();
cin>> input;


switch (input)
{
case 1:
getTime12Format();
break;

case 2:
getTime24Format();
break;
  
case 99:
exit(0);
  
default:
cout<<"Invalid Option!!";
break;
}

return 0;
}

void DisplayChoices(){
cout<< "press 1 to convert from 12-hour to 24-hour notation or"<<endl;
cout<< "press 2 to convert from 24-hour to 12-hour notation"<<endl;
cout<< "Enter 99 to exit the program"<<endl;
}

void getTime12Format(){
int hours;
cout<< "Time in hours: ";
cin>> hours;

int minutes;
cout<< "Time in minutes: ";
cin>> minutes;

int seconds;
cout<< "Time in seconds: ";
cin>> seconds;

string AMorPM;
cout<< "AM or PM: ";
cin>>AMorPM;
ConversionFrom12to24(minutes, hours, seconds, AMorPM);
}

void getTime24Format(){
int hours;
cout<< "Time in hours: ";
cin>> hours;

int minutes;
cout<< "Time in minutes: ";
cin>> minutes;

int seconds;
cout<< "Time in seconds: ";
cin>> seconds;
ConversionFrom24to12(minutes, hours, seconds);
}

void ConversionFrom24to12(int minutes, int hours, int seconds){
string AMorPM = "";

if(hours>12){
AMorPM = "PM";
hours = hours%12;
}
else
{
AMorPM = "AM";
hours = hours;
}
  

Display24to12(minutes, hours, seconds, AMorPM);
}

void ConversionFrom12to24(int minutes, int hours, int seconds, string AmorPm){

if(AmorPm == "PM"){
hours = hours + 12;
}
else
{
hours = hours;
}
  
Display12to24(minutes, hours, seconds);
}

void Display12to24(int minutes, int hours, int seconds){
char zero = ' ';
char hour_zero = ' ';
  
if(hours < 10){
hour_zero = '0';
}
if(minutes < 10)
{
zero = '0';
}
  
cout<<"Time: "<<hour_zero<<hours<<":"<<zero<<minutes<<":"<<seconds<<endl;

}

void Display24to12(int minutes, int hours, int seconds, string AMorPM){
char zero = ' ';

if(minutes<10){
zero = '0';
}

cout<<"Time: "<<hours<<":"<<zero<<minutes<<":"<<seconds<<AMorPM<<endl;
}

Add a comment
Know the answer?
Add Answer to:
Need some assistance of reorganizing this whole program. I have the right code for everything I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the Code using C Program: 2. Write a program to convert the time from 24-hour...

    Create the Code using C Program: 2. Write a program to convert the time from 24-hour notation to 12-hour notation and vice-versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the...

  • 1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice...

    1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following functions: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h>...

    I have a program that needs comments added to it: #include <iostream> #include <stdio.h> #include <conio.h> #include <windows.h> using namespace std; int main() { int m, s,h; cout << "A COUNTDOWN TIMER " << endl; cout << "enter time in hours here" << endl; cin >> h; cout << "enter time in minutes here " << endl; cin >> m; cout << "enter time in seconds here" << endl; cin >> s; cout << "Press any key to start" <<...

  • Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;   ...

    Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;    minutes = 0;    isAfternoon = false;    //check to make sure there are 5 characters    if (//condition to check if length of string is wrong)    {        cout << "You must enter a valid military time in the format 00:00" << endl;    }    else    {        //check to make sure the colon is in the correct...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • so i have my c++ code and ive been working on this for hours but i...

    so i have my c++ code and ive been working on this for hours but i cant get it to run im not allowed to use arrays. im not sure how to fix it thank you for the help our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT