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:
Enjoy the simple code for making a simple calculator using C++. :dance3:
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: