0% found this document useful (0 votes)
23 views1 page

FUNCTION Calculater: Using Namespace Double Double Double Char Int Char Double

FUNCTION Calculater

Uploaded by

prince khan
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)
23 views1 page

FUNCTION Calculater: Using Namespace Double Double Double Char Int Char Double

FUNCTION Calculater

Uploaded by

prince khan
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/ 1

FUNCTION calculater

#include<iostream>
#include<cmath>
using namespace std;
double cal_Fun(double a, double b, char op);
int main()
{
char choice = '+';
double nr1, nr2 = 0.0;
cout << "Please input two numbers and an operator: "<<endl;
cout << "Number 1: ";
cin >> nr1;
cout << "Number 2: ";
cin >> nr2;
cout << "Operator (+ - * / ^ Q for quit): ";
cin >> choice;
while (choice != 'Q')
{
cout << "Result: " << cal_Fun(nr1, nr2, choice) << endl;
cout << "Please input two numbers and an operator: "<<endl;
cout << "Number 1: ";
cin >> nr1;
cout << "Number 2: ";
cin >> nr2;
cout << "Operator (+ - * / ^ Q for quit): ";
cin >> choice;
}
system("PAUSE");
return 0;
}
double cal_Fun(double a, double b, char op)
{
double result = 0.0;
if (op == '+'){
result = a + b;
}
else if (op == '-'){
result = a - b;
}
else if (op == '*'){
result = a * b;
}
else if (op == '/'){
result = a / b;
}
else if (op == '^'){
result = pow(a, b);
}
else{
cout << "Rubbish operator mate please kindly try again! " << endl;
}
return result;
}

You might also like