How to make a calculator using C++

Can you help me with my project in making a calculator using C++

Page 1 of 1

4 Replies - 22214 Views - Last Post: 22 September 2010 - 05:33 AM Rate Topic: -----

#1 jayar_chaos900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-September 10

How to make a calculator using C++

Posted 22 September 2010 - 12:41 AM

#include <iostream.h>
#include <conio.h>
int mc(int x, int y) //Multiply two numbers
{
	cout <<"\n\n"<< x <<" times "<< y <<" equals ";
	return (x*y);
}
int ac(int a, int B)/> //Add two numbers
{
	cout <<"\n\n"<< a <<" plus "<< b <<" equals ";
	return (a+B)/>;
}
int sc(int z, int c) //Subtract two numbers
{
	cout <<"\n\n"<< z <<" minus "<< c <<" equals ";
	return (z-c);
}
int dc(int o, int t) //Divide two numbers
{
	cout <<"\n\n"<< o <<" divided by "<< t <<" equals ";
	return (o/t);
}
void calc(char choice)
{
	int on,tw,thr;
		if (choice == '+') //This whole block checks what the user wants to calculate, and refers to the proper routine to calculate it.
	{
		cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces,";
		cout<<"that you want to add."<<endl;//print instructions for the user
		cin>>on;//Get the value of variable on
		cin>>tw;//Get the value of variable tw
		thr=ac(on,tw);//Get the sum of on and tw, and assign that value to thr
		cout<<thr<<"\n\n\n\aThanks for using my calculator!";//Print a thank you message
	}
	else if (choice =='-')
	{
		cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to subtract."<<endl;
		cin>>on;
		cin>>tw;
		thr=sc(on,tw);
		cout<<thr<<"\n\n\n\aThanks for using my calculator!";
	}
	else if (choice =='*')
	{
		cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to multiply."<<endl;
		cin>>on;
		cin>>tw;
		thr=mc(on,tw);
		cout<<thr<<"\n\n\n\aThanks for using my calculator!";
	}
	else if (choice =='/')
	{
		cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to divide."<<endl;
		cin>>on;
		cin>>tw;
		thr=dc(on,tw);
		cout<<thr<<"\n\n\n\aThanks for using my calculator";
	}
	else
	{
		cout<<"\nPlease reenter that value.\n\a";
		cin>>choice;
		calc(choice,);
	}
}
void main()
{
	clrscr();
	int one, two, three;
	char choice;
	while (choice != 'e')
	{
		cout<<"\nPlease enter +,-,*, or / and then two numbers,\nsepperated by spaces, that you wish to\nadd,subtract,multiply,or divide.\nType e and press enter to exit.";
		cin>>choice;
		if (choice != 'e')
		{
			calc(choice);
		}		
	}
}


This post has been edited by no2pencil: 22 September 2010 - 01:27 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: How to make a calculator using C++

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: How to make a calculator using C++

Posted 22 September 2010 - 12:46 AM

Welcome to DIC!

Please edit your posting (see the "EDIT" button in lower right).
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this :code:
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.


Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details and, ideally, examples.
Was This Post Helpful? 1
  • +
  • -

#3 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: How to make a calculator using C++

Posted 22 September 2010 - 04:32 AM

int ac(int a, int B)/> //Add two numbers
{
	cout <<"\n\n"<< a <<" plus "<< b <<" equals ";
	return (a+B)/>;
}

"B" is different then "b".

calc(choice,);

Extra comma.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: How to make a calculator using C++

Posted 22 September 2010 - 04:54 AM

The capital B is a bug in the system related to smilies.
Was This Post Helpful? 0
  • +
  • -

#5 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: How to make a calculator using C++

Posted 22 September 2010 - 05:33 AM

View PostJackOfAllTrades, on 22 September 2010 - 07:54 AM, said:

The capital B is a bug in the system related to smilies.


My bad, I didn't know.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1