-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path95.cpp
More file actions
35 lines (32 loc) · 679 Bytes
/
Copy path95.cpp
File metadata and controls
35 lines (32 loc) · 679 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
#include <iostream>
using namespace std;
// function declaration
// for dividing two numbers
void divide(double a, double b);
int main()
{
double a, b;
//getting input
cout << "Enter a : ";
cin >> a;
cout << "Enter b : ";
cin >> b;
//calling the function divide()
divide(a, b);
return 0;
}
//function definition
void divide(double a, double b)
{
try //starting of try block
{
if (!b)
throw b; //throwing an exception if denominator is zero
cout<<"Result : "<<a/b<<endl;
}
catch(double d)
{
//handling the exception
cout<<"Cannot divide by zero!!"<<endl;
}
}