1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
using namespace std;
int getTime(int &hours, int &minutes);
void convertTime(int hours, int minutes);
void printTime(int hours, int minutes, char display);
int main()
{
int hours, minutes;
char display;
cout << "---------------------------------------------------------" << endl;
cout << " 24-Hour to 12-Hour Time Converter " << endl;
cout << "---------------------------------------------------------" << endl;
getTime(hours, minutes);
convertTime(hours, minutes);
printTime(hours, minutes, display);
return 0;
}
int getTime(int &hours, int &minutes)
{
cout << "Please enter the hour and minutes in 24-Hour format" << endl;
cin >> hours, minutes;
return hours, minutes;
}
void convertTime(int hours, int minutes)
{
char display;
if(hours > 12)
{
hours = hours - 12;
display = 'PM';
}
else
{
display = 'AM';
}
}
void printTime(int hours, int minutes, char display)
{
cout << "The time converted to a 12 hour format is: " << hours << ":" << minutes << display << endl;
}
|