-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcase2.cpp
More file actions
42 lines (36 loc) · 737 Bytes
/
case2.cpp
File metadata and controls
42 lines (36 loc) · 737 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
/* multiple throws and multiple catches
*
* /*
* WAP to input only +ve numbers.
* If user inputs -ve number show -- "Negative Numbers Not Allowed" as exception
* If user inputs 0 number show -- "Zero Not Allowed" as exception
*/
#include<iostream>
using namespace std;
int main()
{
int PN;
cout<<"Input any positive number"<<endl;
cin>>PN;
try
{
if(PN<0)
throw 1;
else
cout<<"You've entered: "<<PN;
}
catch(int x)
{
cout<<endl<<"Negative Numbers Not Allowed"<<endl<<endl;
}
try
{
if(PN==0)
throw 1.1f;
}
catch(float y)
{
cout<<endl<<"Zero Not Allowed"<<endl<<endl;
}
return 0;
}