 # Thread: C++ Calculator For Beginner

1. ## C++ Calculator For Beginner

C++ calculator code for beginner
Write a simple C++ program which have four
different functions for basic operations like
multiplication.
to enter option and if user enters a wrong
option a proper message to enter right
option should be displayed.

Program explanation..

Program has four different function for each

calculator operation
do while loop is used to display menu options
if else statement is used to check option
Program has two variables on which all
basic operations are applied
and return result

C++ source code compiler used Codeblocks

#include <iostream>
using namespace std;
int addition (int num1, int num2);
int subtraction (int num1, int num2);
int division (int num1, int num2);
int multiplication(int num1, int num2);
int main()
{
char option;
int num1, num2, result;
cout<<"\n\t\t\tSimple calculator"<<endl;
do
{
cout<<"Enter + for Addtion\nEnter - for Subtraction\n
Enter / for Division\nEnter * for Multiplication\n
Enter E to EXIT\n";
cout<<"\n\t\t\tEnter Option: ";
cin>>option;
if(option!='e'&&option!='E')
{
cout<<"\n\t\t\tEnter First Number: ";
cin>>num1;
cout<<"\n\t\t\tEnter Second Number: ";
cin>>num2;
}
if(option!='+'&&option!='-'&&option!='/'
&&option!='*'&&option!='e'&&option!='E')
{
cout<<"\n\t\t\tSELECT the VALID OPTION\n";
}
else if(option=='+')
{
cout<<"\n\t\t\t"<<num1<<" + "<<num2<<" = "<<result<<endl;
}
else if(option=='-')
{
result=subtraction(num1,num2);
cout<<"\n\t\t\t"<<num1<<" - "<<num2<<" = "<<result<<endl;
}
else if(option=='/')
{
result=division(num1,num2);
cout<<"\n\t\t\t"<<num1<<" / "<<num2<<" = "<<result<<endl;
}
else if(option=='*')
{
result=multiplication(num1,num2);
cout<<"\n\t\t\t"<<num1<<" X "<<num2<<" = "<<result<<endl;
}
}while(option!='e'&&option!='E');
cout<<"\n\t\t\tProgram EXIT Successfully.......\n\t\t\t";
return 0;
}
{
return (num1+num2);
}
int subtraction(int num1, int num2)
{
return (num1-num2);
}
int division(int num1, int num2)
{
if(num2==0)
{
cout<<"\n\t\t\tDivide by ZERO not allowed :"<<endl;
return 0;
}
return (num1/num2);
}
int multiplication(int num1, int num2)
{
return (num1*num2);
}

Program Output: Last edited by A_Qayoom; 13th August 2016 at 06:46 PM. Reason: ScreenShot Link Changed  Reply With Quote

2. ## Great  Reply With Quote

3. ##  WhoWaleedSaid said: Great
Tks  Reply With Quote

4. ## Very Good  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
•