Calculator

Hey guys, i'd be glad if you can tell me whats the problem withs my calculator ,
thanks.

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
 #include <iostream>
#include <cmath>

using namespace std;

int main()
{
	//fen: first entered number. sen:second entered number. ma:mathematical action

	double fen, sen;
	double a, b, c, d;
	char ma;
	//a - sum outcome. b - difference outcome c - multipication outcome d - division outcome

	a = fen + sen;
	b = fen - sen;
	c = fen*sen;
	d = fen / sen;

	cout << "Welcome to the world finest calculator\n";
	cout << "Please enter the mathematical calculation you want to perform, using + for sum, - for difference, * for multipication and / for division\n";
	cin >> fen >> ma >> sen;

	if (ma = '+')
		cout << "The sum of the numbers is:" << a << endl;
	if (ma = '-')
		cout << "The difference of the two numbers is:" << b << endl;
	if (ma = '*')
		cout << "The multipication of the two numbers is:" << c << endl;
	if (ma = '/' )
		cout << "The division of the two numbers is:" << d << endl;

	cout << "Thank you for using the world best calculator" << endl;

	
		return 0;




}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        a = fen + sen;
	b = fen - sen;
	c = fen*sen;
	d = fen / sen;

	cout << "Welcome to the world finest calculator\n";
	cout << "Please enter the mathematical calculation you want to perform, using + for sum, - for difference, * for multipication and / for division\n";
	cin >> fen >> ma >> sen;

	if (ma = '+')
		cout << "The sum of the numbers is:" << a << endl;
	if (ma = '-')
		cout << "The difference of the two numbers is:" << b << endl;
	if (ma = '*')
		cout << "The multipication of the two numbers is:" << c << endl;
	if (ma = '/' )
		cout << "The division of the two numbers is:" << d << endl;


You work out the outputs (a, b, c, d) ... before you enter the inputs (fen, sen)! Your code shows great anticipation!

Try stepping through your code in order, line by line and you will see this.
Topic archived. No new replies allowed.