برنامه ماشین حساب

کد برنامه:

#include <iostream.h>
#include <conio.h>
void sum(float &x, float &y)
{ float s;
cout<<"Enter two numbers ";
cin>>x>>y;
clrscr ();
cout<<"x= "<<x<<"\ty= "<<y<<"\n\n";
s=x+y;
cout<<x<<" + "<<y<<" = "<<s;
}
void sub(float &x, float &y)
{ float su;
cout<<"Enter two numbers ";
cin>>x>>y;
clrscr ();
cout<<"x= "<<x<<"\ty= "<<y<<"\n\n";
su=x-y;
cout<<x<<" - "<<y<<" = "<<su;
}
void mul(float &x, float &y)
{ float m=0;
cout<<"Enter two numbers ";
cin>>x>>y;
clrscr ();
cout<<"x= "<<x<<"\ty= "<<y<<"\n\n";
m=x*y;
cout<<x<<" * "<<y<<" = "<<m;
}
void div (float &x, float &y)
{ float d=0,y2,d2;
cout<<"Enter two numbers ";
cin>>x>>y;
clrscr ();
cout<<"x= "<<x<<"\ty= "<<y<<"\n\n";
if(y!=0)
{d=x/y;
cout<<x<<" / "<<y<<" = "<<d;}
else
if(y==0)
{cout<<"Zero can't be used in division\n\n";
cout<<"Enter another y ";
cin>>y2;
d2=x/(y2);
cout<<x<<" / "<<y2<<" = "<<d2;}
}
void main()
{ float x,y;
unsigned z;
cout<<"Enter the neumber of operation from the list below to be done:\n\n";
cout<<"1-Sumation\n\n2-Substraction\n\n3-Multiplication\n\n4-Division\n\n";
cin>>z;
clrscr ();
switch(z)
{ case 1: sum(x,y);
break;
case 2: sub(x,y);
break;
case 3: mul(x,y);
break;
case 4: div(x,y);
break;
default: cout<<"Enter a number between 1 and 4";
}
}

/ 0 نظر / 5 بازدید