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
|
#include <iostream>
#include <cmath>
using namespace std;
void input(int& hours24, int& minutes);
void convert(int& hours, char& AMPM);
void output(int hours, int minutes, char AMPM);
int main() {
cout << "-----------------------------Convert from 24-hour format to 12 hour format--------------------\n";
int hour, min,
char choice, AMPM;
do {
void input(hour, min);
void convert(hour, min, AMPM);
void output(hour, min, AMPM);
cout << "/n";
cout << "To complete press y or Y: "; cin >> choice;
} while (choice == 'Y' || choice == 'y');
}
void input(int& hours24, int& minutes) {
cout << "Enter your time in hours and minutes"; cin >> hours24; cin >> minutes;
}
void convert(int& hours, char& type) {
if (hours > 12) {
hours -= 12;
type = 'P';
}
else {
type = 'A';
}
}
void output(int hours, int minutes, char type) {
cout << "In 12 hour notation: " << hours << ":" << minutes << " " << type << "";
}
|