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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <cmath>
#include <iostream>
#include <string>
void input(int& min, int& hours, int& wait_hours, int& wait_min);
void calc(int& total_hours,
int& hours,
int& min,
int& wait_hours,
int& wait_min,
int& total_min);
void output(int& total_hours, int & total_min, char & anwser);
int main()
{
char anwser;
do {
int min, hours, wait_hours, wait_min, total_hours, total_min;
input(min, hours, wait_hours, wait_min);
calc(total_hours, hours, min, wait_hours, wait_min, total_min);
output(total_min, total_hours, anwser);
} while (toupper(anwser) == 'Y');
}
void input(int& min, int& hours, int& wait_hours, int& wait_min)
{
std::cout << "Compute completion time from current time and waiting period"
"\nEnter 24 hour time in the format of HH:MM: ";
char c;
std::cin >> hours >> c >> min;
std::cout << "Enter in a waiting time in the format of HH:MM: ";
std::cin >> wait_hours >> c >> wait_min;
}
void calc(int& total_hours,
int& hours,
int& min,
int& wait_hours,
int& wait_min,
int& total_min)
{
total_hours = hours + wait_hours;
total_min = min + wait_min;
if (total_hours > 24)
{
total_hours -= 24;
}
else if (total_min > 60)
{
total_min -= 60;
}
if (hours > 24 || min > 60)
{
std::cout << "Error!\n";
std::abort(); // std::exit() ?
}
}
void output(int& total_hours, int& total_min, char& anwser)
{
std::cout << "Completion time in 24 hour format is: "
<< total_hours << ":" << total_min
<< "\nWould you like to do this this again? Press Y for yes or "
"N for no: ";
std::cin >> anwser;
}
|