need tips on how to make calculator work

Unlike my previous calculator this is supposed to do basic operations, but its not working. can someone tell me whats wrong?

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
#include "stdafx.h"


#include <iostream>
using namespace std;

int main ()
{
	//first number
	 short int a;
	// operation	
	short int b;
	//second number		
	short int c;

		cout << "Select your first number";
		cin >> a;

			cout << "Select the operation";
			cout << "1= add, 2= sub, 3= multiply, 4= divide;
			cin >> b;

				cout << "Select the second number";
				cin >> c;

				if b= 1 cout << " Your Result is" << a + c;
				if b= 2 cout << " Your Result is" << a - c;
				if b= 3 cout << " Your Result is" << a * c;
				if b= 4 cout << " Your Result is" << a / c;

				cin.ignore(LONG_MAX,'\n');
				cin.get ();
					return 0;
				
} 
You're missing your closing " on this line:

cout << "1= add, 2= sub, 3= multiply, 4= divide;
it should be like this
cout << "1= add, 2= sub, 3= multiply, 4= divide";

u miss d double qoute.thats basic..
Perhaps you should try compiling it first?

You have several syntax errors to fix beyond what was previously mentioned.
here is the working 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

#include <iostream>
using namespace std;

int main ()
{
	//first number
	 short int a;
	// operation	
	short int b;
	//second number		
	short int c;

		cout << "Select your first number ";
		cin >> a;

			cout << "Select the operation ";
			cout << "1= add, 2= sub, 3= multiply, 4= divide";
			cin >> b;

				cout << "Select the second number ";
				cin >> c;

				if (b== 1) cout << " Your Result is " << a + c;
				if (b== 2) cout << " Your Result is " << a - c;
				if (b== 3) cout << " Your Result is " << a * c;
				if (b== 4) cout << " Your Result is " << a / c;

				cin.ignore(LONG_MAX,'\n');
				cin.get ();
					return 0;
    }

Your Mistakes:
1) = is not same as ==
2) put the condition of if in parenthesis

Topic archived. No new replies allowed.