0% found this document useful (0 votes)
42 views5 pages

Javeria Ismail (20) .Calculator

This document discusses how to create a basic calculator program using functions in C++. It includes functions for addition, subtraction, multiplication, and division that take in two double parameters and return the result of the operation. The main function prompts the user to select an operation, enters two numbers, calls the corresponding function and displays the output. This allows each calculation to be performed modularly by separate functions while the main program handles the user interface and flow.

Uploaded by

Mehwish Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

Javeria Ismail (20) .Calculator

This document discusses how to create a basic calculator program using functions in C++. It includes functions for addition, subtraction, multiplication, and division that take in two double parameters and return the result of the operation. The main function prompts the user to select an operation, enters two numbers, calls the corresponding function and displays the output. This allows each calculation to be performed modularly by separate functions while the main program handles the user interface and flow.

Uploaded by

Mehwish Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming Fundamentals

Functions

Submitted To:
Mr. Amir Jamshaid

Submitted by:
Javeria Ismail
Roll#: 20
Q1:write a program to make calculator by using function for
each operation of calculator?
#include<iostream.h>

#include<conio.h>

Double add(double,double);

Double sub(double,double);

Double mul(double,double);

Double div(double,double);

Void main()

Clrscr();

Double sum=0,subt=0,product=0,dvs=0,num1=0,num2=0;

Int choice;

Cout<<”\n enter operation choice that want to perform:”;

Do

Cout<<”\n 1----> addition:”;

Cout<<”\n 2----> subtraction:”;

Cout<<”\n 3----> multiplictation:”;

Cout<<”\n 4----> division:”;

Cin>>choice;

If (choice==0)

Break;
}

Cout<<”\n enter first value:”;

Cin>>num1;

Cout<<”\n enter 2nd value:”;

Cin>>num2;

If (choice==1)

Sum=add(num1,num2);

Cout<<”\n sum is:”<<sum;

Else if (choice==2)

Subt=sub(num1,num2);

Cout<<”\n subtraction is:”<<subt;

Else if (choice==3)

Prdct=mul(num1,num2);

Cout<<”\ prodct is:”<<prdct;

Else if (choice==4)

Dvs =div (num1,num2);

Cout<<”\n division is:”<<dvs;


}

Else

Cout<<”\n invalid choice:”;

While (choice!=0);

Getch();

Double add (double n1,double n2)

Double s;

S=n1+n2;

Return s;

Double sub (double n1,doublen2)

Double d;

D=n1-n2;

Return d;

Double mul (double n1,n2)

Double pro;
Pro=n1*n2;

Return pro;

Double div (double n1,n2)

Double divs;

Divs =n1/n2;

Return divs;

You might also like