-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception.cpp
126 lines (105 loc) · 2.11 KB
/
exception.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// exception handling - 19.2.24
/*
#include <iostream>
using namespace std;
int main()
{
// throw, catch,, if-else doesn't end the program gracefully
float i = 11;
float j, ans;
cout << "Enter a number" << endl;
cin >> j;
try
{
ans = i / j;
cout << ans << endl;
if (j == 0)
throw 420;
else
ans = i / j;
}
catch (int e)
{
cerr << " Error! " << e << '\n';
cout << "Wrong denominator entered" << endl;
}
}
*/
/*
// program that gives 3 pin attempts
// made a program that gives 3 attempts to enter your pin
#include <iostream>
using namespace std;
int main()
{
int PWD = 1001;
int pin;
for (int i = 0; i < 3; i++)
{
cin >> pin;
try
{
if (pin != PWD)
throw "wrong !!";
else
cout << "Right Pin !!";
break;
}
catch (const char *e) // const char* is for char. int e is for integers
{
cerr << e << endl;
}
}
}
*/
/*
#include <iostream>
using namespace std;
int main()
{
int n;
const int pass = 4231;
cout << "Enter your pin: ";
cin >> n;
if (cin.fail()) // this is to check if we are entering the correct data type
{
cerr << "Error. Invalid data type written" << endl;
return 1;
}
try
{
if (n == pass)
cout << "right answer";
else
throw "Bokoka";
}
catch (const char* e)
{
cerr << e << '\n';
}
}
*/
#include <iostream>
using namespace std;
int main()
{
string word;
const string pass = "bahubali";
cout << "Enter your password: ";
cin >> word;
if (cin.fail()) // this is to check if we are entering the correct data type
{
cerr << "Error. Invalid data type written" << endl;
}
try
{
if (word == pass)
cout << "Jai Mahishmati";
else
throw "enti maava";
}
catch (const char *e)
{
cerr << e << '\n';
}
}