-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeNotes.cpp
More file actions
60 lines (43 loc) · 1.76 KB
/
timeNotes.cpp
File metadata and controls
60 lines (43 loc) · 1.76 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
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int main() {
//time in seconds since jan 1st, 1970
int currTime = time(0);//take input 1 number: is the number of seconds into the future , returns that future time
cout << currTime <<endl; //time since 170 jan 1st in seconds
/* VALIDATING INPUT NOTES */
int a;
cout << "enter a number: ";
cin >> a;
cout << "Your number was: " << a << endl;
// short short: 000 if integer overflow: number goes back to 0
// if 3 bits, 8 is stored as 000
/* CIN's FAIL PROPERTIES !!!!!!!!!!!!! */
int x;
int y;
string theRestOfInputBuffer;
cout << "type 2 nums seperated by a space: ";
cin >> x >> y; //if inputted data type doesnt not match data type that cin is assigning to, cin raises an internal flag
//// cin.fail();//asks if flag was raised, evals to bool
//cin >> theRestOfInputBuffer; // stores the flagged cin input in theRestOfInputBuffer
//cout << "The incorrect input: " << theRestOfInputBuffer << endl;
while (cin.fail()) {
//cin >> theRestOfInputBuffer; // stores the flagged cin input in theRestOfInputBuffer
//cout << "The incorrect input: " << theRestOfInputBuffer << endl;
cout << "you did not type an int. Try again: " << endl;
cin.clear(); // clears memory in cin containing the raised error, or resetting the fail() flag
cin.ignore(10 - 0000, '\n'); //resetting terminal so they can try again? w/o it cuases an infinite loop
cin >> x >> y;
/* USER vALIDATION FUNCTS to STUDY: !!!!!
getline()
cin.get()
cin.peek()
cin.fail()
cin.ignore()
cin.clear()
*/
}
cout << x << " " << y << endl;
return 0;
}