-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptional Handling.cpp
More file actions
60 lines (47 loc) · 981 Bytes
/
Exceptional Handling.cpp
File metadata and controls
60 lines (47 loc) · 981 Bytes
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
// Date: 22-November-2018
//if the subject marks are less than 0 or more than 100 give an exception
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int p = 0, c = 0, m = 0;
while (((p <= 0) || (p >= 100)) || ((c <= 0) || (c >= 100)) || ((m <= 0) || (m >= 100)))
{
try
{
cout << "Physics marks: ";
cin >> p;
if ((p < 0) || (p > 100))
{
throw(0);
}
cout << "chemistry marks: ";
cin >> c;
if ((c < 0) || (c > 100))
{
throw(0);
}
cout << "math marks: ";
cin >> m;
if ((m < 0) || (m > 100))
{
throw(0);
}
}
catch (int e)
{
cout << "invalid marks" << endl;
}
}
cout << endl;
cout << "physics" << p << endl;
cout << "chemistry" << c << endl;
cout << "maths" << m << endl;
system("pause");
return 0;
ofstream myfile;
myfile.open("lab.txt");
myfile << p << endl << c << endl << m << endl;
return 0;
}