forked from dscmsit/Problem-Solving-in-any-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeclock.cpp
More file actions
78 lines (69 loc) · 1.47 KB
/
Timeclock.cpp
File metadata and controls
78 lines (69 loc) · 1.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <iomanip>
using namespace std;
class Time
{
private:
int hours;
int minutes;
int seconds;
public:
int get_time();
void put_time();
};
int Time::get_time()
{
cout << "Enter hours: ";
cin >> hours;
if ( std::cin.fail() ) {
cout << "Error entering hours\n";
cin.clear();
cin.ignore();
return -1;
}
if (hours < 0 || hours > 23) {
cout << "Incorrect hours value\n";
return -1;
}
cout << "Enter minutes: ";
cin >> minutes;
if ( std::cin.fail() ) {
cout << "Error entering minutes\n";
cin.clear();
cin.ignore();
return -1;
}
if (minutes < 0 || minutes > 59) {
cout << "Incorrect minutes value\n";
return -1;
}
cout << "Enter seconds: ";
cin >> seconds;
if ( std::cin.fail() ) {
cout << "Error entering seconds\n";
cin.clear();
cin.ignore();
return -1;
}
if (seconds < 0 || seconds > 59) {
cout << "Incorrect seconds value\n";
return -1;
}
return 0;
}
void Time::put_time()
{
cout << setfill('0') << setw(2) << hours << ":"
<< setfill('0') << setw(2)<< minutes << ":"
<< setfill('0') << setw(2) << seconds << endl;
}
int main()
{
Time t;
int res;
while(1) {
if (t.get_time() == 0) {
t.put_time();
}
}
return 0;}