Calculator doesn't work

Hi guys, im having an issue by creating a calculator. I'm an absolute beginner since I just started learning Programming some days ago. Can someone tell me what's wrong in this code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdlib>
#include <iostream>

using namespace std;

int addition(int num1, int num2)
{
	return num1 + num2;
}
int subtraction(int num1, int num2)
{
	return num1 - num2;
}
int multiplication(int num1, int num2)
{
	return num1 * num2;
}
int division(int num1, int num2)
{
	return num1 / num2;
}

int main()
{
	int number1;
	int number2;
	//Addition
	cout << "You are adding. Enter the first number you would like to add. \n Number 1: ";
	cin >> number1;
	cout << " Enter the second number. \n Number 2: ";
	cin >> number2;
	cout << " The answer is: " << addition(number1, number2) << endl;

		//Subtraction
	cout << "You are subtracting. Enter the first number you would like to subtract. \n Number 1: ";
	cin >> number1;
	cout << " Enter the second number. \n Number 2: ";
	cin >> number2;
	cout << " The answer is: " << subtraction(number1, number2) << endl;

		//Multiplication
	cout << "You are adding. Enter the first number you would like to multiply. \n Number 1: ";
	cin >> number1;
	cout << " Enter the second number. \n Number 2: ";
	cin >> number2;
	cout << " The answer is: " << multiplication(number1, number2) << endl;

		//Division
	cout << "You are dividing. Enter the first number you would like to divide. \n Number 1: ";
	cin >> number1;
	cout << " Enter the second number. \n Number 2: ";
	cin >> number2;
	cout << " The answer is: " << division(number1, number2) << endl;

}

When I run it, it prints : 10Press
any key to continue...
Last edited on
That is quite odd. Have you compiled it? Maybe you are running your previous program. And when posting code, please select it and press the <> button (then it gets formatted).
I fixed the topic.. but im always compiling before running, so .. i'm pretty sure that im not running the previous one.

Well, i just tried in Bloodshed Dev C++ and it worked, but it didnt work on Visual C++ 2010 Express.
Last edited on
1
2
3
4
int subtraction(int num1, int 2)
{
return num1 - num2;
}


should be:

1
2
3
4
int subtraction(int num1, int num2)
{
return num1 - num2;
}


what do you mean it prints 10?
yes, I noticed that when compiling in Bloodshed Dev C++. When I tried in Visual C++ Express, it didn't show any error, and the result was different from Bloodshed Dev C++.

Bloodshed Dev C++ worked properly
Visual C++ 2010 Express did not work properly.. i don't know why.


I mean that everything that shows in the console is :

"10Press any key to continue"

Last edited on
Topic archived. No new replies allowed.