-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem43.c++
More file actions
52 lines (46 loc) · 1.38 KB
/
Problem43.c++
File metadata and controls
52 lines (46 loc) · 1.38 KB
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
#include <iostream>
#include <string>
using namespace std;
struct strTaskDuration
{
int NumberOfDays, NumberOfHours, NumberOfMinutes, NumberOfSeconds;
};
int ReadPositiveNumber(string Message)
{
float Number = 0;
do
{
cout << Message << endl;
cin >> Number;
} while (Number <= 0);
return Number;
}
strTaskDuration SecondsToTaskDuration(int TotalSeconds)
{
strTaskDuration TaskDuration;
const int SecondsPerDay = 24 * 60 * 60;
const int SecondsPerHours = 60 * 60;
const int SecondsPerMinute = 60;
int Remainder = 0;
TaskDuration.NumberOfDays = floor(TotalSeconds / SecondsPerDay);
Remainder = TotalSeconds % SecondsPerDay;
TaskDuration.NumberOfHours = floor(Remainder / SecondsPerHours);
Remainder = Remainder % SecondsPerHours;
TaskDuration.NumberOfMinutes = floor(Remainder / SecondsPerMinute);
Remainder = Remainder % SecondsPerMinute;
TaskDuration.NumberOfSeconds = Remainder;
return TaskDuration;
}
void PrintTaskDurationDetils(strTaskDuration TaskDuration)
{
cout << endl;
cout << TaskDuration.NumberOfDays << ":"
<< TaskDuration.NumberOfHours << ":"
<< TaskDuration.NumberOfMinutes << ":"
<< TaskDuration.NumberOfSeconds << "\n";
}
int main()
{
int TotalSeconds = ReadPositiveNumber("Pleas Enter Total Seconds?");
PrintTaskDurationDetils(SecondsToTaskDuration(TotalSeconds));
}