Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- void enter();
- void divbz();
- void enter()
- {
- int i=0,counta=0,countb=0;
- int c,d;
- float a,b;
- cout<<"enter two float values\n";
- cin>>a>>b;
- c=(int)a;
- d=(int)b;
- a=a-c;
- b=b-d;
- try
- {
- if((a==0)||(b==0))
- throw 1;
- else
- throw 0;
- }
- catch(int x)
- {
- switch(x)
- {
- case 0:
- cout<<"correct data type entered\n";
- break;
- case 1:
- cout<<"wrong data type entered \n";
- break;
- default:
- break;
- }
- }
- }
- void divbz()
- {
- int z,x;
- cout<<"enter two numbers to divide them\n";
- cin>>z>>x;
- try
- {
- if(x==0)
- throw x;
- else
- cout<<"the quotient is "<<(z/x)<<endl;
- }
- catch(int m)
- {
- cout<<"cannnot divide the divisor is "<<m<<endl;
- }
- }
- int main()
- {
- enter();
- divbz();
- return 0;
- }
- OUTPUT:
- enter two float values
- 3.461
- 2.615
- correct data type entered
- enter two numbers to divide them
- 4
- 0
- cannnot divide the divisor is 0
- enter two float values
- 4
- 2
- wrong data type entered
- enter two numbers to divide them
- 456
- 421
- the quotient is 1
Advertisement
Add Comment
Please, Sign In to add comment