# Thread: C++ code for a simple calculator

1. ## C++ code for a simple calculator

guys, just few mins before I was searching on internet for a simple C code to make a simple calculator to reply on the thread that Mehul has opened: http://offlinemarketingforum.com/c-c...success-c.html and found some codes of a simple calculator which can perform addition, subtraction, multiplication and division both on C and C++.

I have shared C code over here: http://offlinemarketingforum.com/c-c...success-c.html and sharing C++ code below:

Code:
```#include <iostream>

using namespace std;

float addition( float num1, float num2)
{ return num1 + num2; }

//subtraction
float subtraction(float num1, float num2)
{return num1-num2;}

//multiplication
float multiplication(float num1, float num2)
{return num1*num2;}

//division
float division(float num1, float num2)
{return num1/num2;}

//main function
int main()
{
float number1;
float number2;
int choice;
cout<<"What would you like to do?(1=add, 2=subtract, 3=multiply, 4=divide)"<<endl;
cout<<"Choice:"<<endl;
cin>>choice;

if(choice==1)
cin>>number1;
cout<<"What would you like to add?"<<endl<<"Number:";
cin>>number2;
else
if(choice==2)
{//subtraction
cout<<"What is your first number(subtraction)?"<<endl<<"Number:";
cin>>number1;
cout<<"What number would you like to subtract?"<<endl<<"Number:";
cin>>number2;
else
if(choice==3)
{//multiplication
cout<<"What is your first number(Multiplication)?"<<endl<<"Number:";
cin>>number1;
cout<<"What number would you like to multiply?"<<endl<<"Number:";
cin>>number2;
else
//division
cout<<"What is your first number(Divide)?"<<endl<<"Number:";
cin>>number1;
cout<<"What number would you like to Divide by?"<<endl<<"Number:";
cin>>number2;

system("PAUSE");
return 0;
}```
Enjoy the simple code for making a simple calculator using C++.   Reply With Quote

2. ## Re: C++ code for a simple calculator

That is a quite large code for me. Don't you have any short code for C++?  Reply With Quote

3. ## Re: C++ code for a simple calculator

Generally C++ codes are huge in size but they are more user friendly than conventional C codes. The code I have shared are very easy, you just go through the code attentively once, I am sure you will understand the code after reading once.

Anyways I am searching on internet to find some more codes and also trying to write one by myself. I will share if I find more easy code over here.  Reply With Quote

4. ## Re: C++ code for a simple calculator

hmm.... I'm like only a day into C++ programming... that code line looks way above my level..  Reply With Quote

5. ## Re: C++ code for a simple calculator

How about making a scientific calculator?   Reply With Quote

6. ## Re: C++ code for a simple calculator

thats would be cool to see.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•