I need help in writing a C++ program that converts 24-hour notation to 12-hour notation. (For example, it should convert 14:25 to 2:25 P.M. The input is given as two integers. There are three functions: one for input, one to do the conversion, and one for output. Record the A.M./P.M. information as a value of type char, 'A' for A.M. and 'P' for P.M. Thus, the function for doing the conversions will have a call-by-reference formal parameter of type char to record whether it is A.M. of P.M. ) Specifically, I need help iin defining the function : int convertTo12Hour(int hours, char& type)
The code I have so far is:
#include <iostream>
using namespace std;
void input(int& hours, int& minutes);
void output(int hours, int minutes, char type);
int convertTo12Hour(int hours, char& type);
int main() {
int hours;
int minutes;
char type;
char answer;
do
{
input(hours, minutes);
hours = convertTo12Hour(hours, type);
output(hours, minutes, type);
cout << "Perform another calculation? (y/n): ";
cin >> answer;
} while ((answer == 'Y') || (answer == 'y'));
return 0;
}
void input(int& hours, int& minutes) {
cout << "Enter the hours for the 24 hour time: ";
cin >> hours;
cout << "Enter the minutes for the 24 hour time: ";
cin >> minutes;
}
//
// Displays a time in 12 hour notation
//
void output(int hours, int minutes, char type) {
cout << "The time converted to 12 hour format is: " << hours << ":";
//
// special handling for leading 0s on the minutes
//
cout.width(2);
cout.fill('0');
cout << minutes;
//
if (type == 'A')
cout << " A.M." << endl;
else
cout << " P.M." << endl;
}
int convertTo12Hour(int hours, char& type);{
but i am stuck on the rest am i on the right track and where do i go from here ?