Condition problems

using namespace std;

const double MAXRANGE = pow(2.0, 16.0); // 65536
const double MINRANGE = -pow(2.0, 16.0);

int main(int argc, char *argv)
{
if (argc == 1)
{
cout << “bunnies” << endl;
return 0;
}

int N1 = 0;
int N2 = 0;
int Result = 0;

if (argc == 3)
{
	Result = N1 + N2;
	cout << Result << endl;
}

if (argc == 4)
{
	if (argv[3][0] == 'a')
	{
		Result = N1 + N2;
		cout << Result << endl;
	}
	if (argv[3][0] == 's')
	{
		Result = N1 - N2;
		cout << Result << endl;
	}
	if (argv[3][0] == 'm')
	{
		Result = N1 * N2;
		cout << Result << endl;
	}
	if (argv[3][0] == 'd')
	{
		Result = N1 / N2;
		cout << Result << endl;
    }
}

if (argc > 4)
{
	cout << "p" << endl;
	return 0;
}

return 0;
}

I am having problems writing one of my conditions the “if (argc == 4)” I need a better way writing this because the debugger skips that whole if statement. btw the code is for a arithmetic calculator which add, subtract, multiply and divide. wondering if someone can help as I am relatively new to coding in C++.

I doubt the if-statement is skipped. Maybe you expected the condition to be satisfied, but it isn’t?

1 Like