# why the calculator is not working properly ?

#include <iostream>

using namespace std;

int

main ()

{

char op;

int a, b, c, d;

cout << "if you are want to open calcutor then enter 1" << endl

<< "if you are want to find maximum number out of three then enter 2" <<

endl << "if you are want to find odd-even then enter 3" << endl;

cin >> d;

switch (d)

{

case 1:

cout << "entar first number" << endl;

cin >> a;

cout << "entar second number" << endl;

cin >> b;

cout << "enter the operation( +,-,*,/)" << endl;

cin >> op;

if (op = '/')

{

cout << a << "/" << b << "=" << (float) a / b << endl;

}

else if (op = '-')

{

cout << a << "-" << b << "=" << a - b << endl;

}

else if (op = '*')

{

cout << a << "*" << b << "=" << a * b << endl;

}

else if (op = '+')

{

cout << a << "+" << b << "=" << a + b << endl;

}

break;

case 2:

cout << "enter three number one by one" << endl;

cin >> a >> b >> c;

if (a > b)

{

if (a > c)

{

cout << "maximum number is\t" << a << endl;

}

else

{

cout << "maximum number is\t" << c << endl;

}

}

else if (b > a)

{

if (b > c)

{

cout << "maximum number is\t" << b << endl;

}

else

{

cout << "maximum number is\t" << c << endl;

}

}

break;

case 3:

cout << "enter any number" << endl;

cin >> a;

if (a % 2 == 0)

{

cout << a << "\tis an even number" << endl;

}

else

{

cout << a << "\tis an odd number" << endl;

}

break;

default:

cout << "invalid number";

}

}

+1 vote
answered Nov 28, 2021 by (55,660 points)

# Assignment vs equality check

The = operator is the assignment operator. It assigns value to a variable. E.g.:

`op = '/'`

The == operator is the equality check operator. It checks if the left side and the right side are equal. E.g.

`op == '/'`

Also, before your finish your main function, you should set the return value as it has an int return type:

`return 0;`