• Please make sure to complete your profile by filling in any details pertaining to your company, name, photo, socials and contact information for any updates.
  • Need a hand with one of our platforms? post it under the support forum!
  • Reach out to us by emailing devsupport@redtorrentmedia.app if you don't see a response in 24/48 hours. - Please forward your thread!

C++ code for a simple calculator

alanmark

New member
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-c/417-my-first-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-c/417-my-first-success-c.html and sharing C++ code below:


Code:
[COLOR="#FFFFFF"]#include <iostream>

using namespace std;

//addition
 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)
    {//addition
    cout<<"What is your first number?(addition)"<<endl<<"Number:";
    cin>>number1;
    cout<<"What would you like to add?"<<endl<<"Number:";
    cin>>number2;
    cout<<"Your Answer is:"<<addition(number1, number2)<<endl;}
   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;
    cout<<"Your Answer is:"<<subtraction(number1, number2)<<endl;}
  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;
    cout<<"Your Answer is:"<<multiplication(number1, number2)<<endl;}
  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;
    cout<<"Your Answer is:"<<division(number1, number2)<<endl;
    
    system("PAUSE");
    return 0;
}[/COLOR]

Enjoy the simple code for making a simple calculator using C++. :dance3:
 

alanmark

New member
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.
 
Top