calculator


cout<<"pls can i use c++ language to write a functional calculator?;
Yes you can, as the language is Turing complete.
here is the code:
#include<iostream>
#include<conio.h>
using namespace std;
int add(int x, int y)
{
int a = x+y;
return a;
}
int sub(int x, int y)
{
int a=x-y;
return a;
}
int mult(int x, int y)
{
int a = x*y;
return a;
}
double diviz(double x, double y)
{
double a = x/y;
return a;
}


int main()
{
int a, b;
cout <<"Enter a, b: "<<endl;
cin>>a>>b;
char c = getch();
switch(c)
{
case '+': cout<<add(a,b);
break;
case '-': cout<<sub(a, b);
break;
case '*': cout<<mult(a, b);
break;
case '/': cout<<diviz(a, b);
break;
default: cout<<"Action? {+ - * /}";
}

getch();
return 0;
}
@alex1205:

May I ask why you gave that to him...


Since he didn't actually do any work himself.

EDIT: http://cplusplus.com/forum/articles/31015/

Last edited on
Topic archived. No new replies allowed.