logo

Assignment On Basic Mathematical Operations

5 Pages460 Words16 Views
   

Added on  2022-10-02

Assignment On Basic Mathematical Operations

   Added on 2022-10-02

ShareRelated Documents
Source Code
#include<iostream>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<iomanip>
char ch;
using namespace std;
void add(float x,float y)
{
float z;
z=x+y;
cout<<"Sum is: "<<z<<endl;
}
void sub(float x,float y)
{
float z;
z=x-y;
cout<<"\nDifference is:"<<z<<endl;
}
void mul(float x,float y)
{
float z;
z=x*y;
cout<<"Product is:"<<z<<endl;
}
void div(float x,float y)
{
float z;
if(y==0)
{
cout<<"Cannot be divided by 0"<<endl;
}
else
{
z=x/y;
cout<<"\nQuotient is:"<<z<<endl;
}
}
int main()
{
float a,b;
do
{
Assignment On Basic Mathematical Operations_1
cout<<"Basic Mathematical Operations \n";
cout<<"Press 1 for addition \n";
cout<<"Press 2 for subtraction\n";
cout<<"Press 3 for multiplication\n";
cout<<"Press 4 for division\n";
cout<<"Press 5 for exit\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case '1':
cout<<"Enter two numbers \n";
cin>> a>>b;
add(a,b);
break;
case '2':
cout<<"Enter two numbers \n";
cin>> a>>b;
sub(a,b);
break;
case '3':
cout<<"Enter two numbers \n";
cin>> a>>b;
mul(a,b);
break;
case '4':
cout<<"Enter two numbers \n";
cin>> a>>b;
div(a,b);
break;
case '5':
exit(0);
default:
cout<<"Invalid input..select a valid input" ;
system("cls");
}
}
while(ch!='0');
getch();
}
Output
Assignment On Basic Mathematical Operations_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Rate of Acceleration Physics Assignment 2022
|6
|960
|17

Organizing Input Output in a Programming Language
|11
|3656
|107

Fundamentals of Programming
|9
|1287
|62

ROBOTICS C++. 1. Robotics C++ Name of Student Instituti
|5
|482
|24

User and Technical Documentation for Health Club Membership Calculator Program
|26
|5023
|395

The order of the substitution
|11
|1382
|18