I was making a simple calculator in C++. However the program does not completely function the way it should. When run, the trig if statement executes fine, however, the basic ar
Change:
if(function == "sin" || "cos" || "tan")
into:
if ((function == "sin") || (function == "cos") || (function == "tan"))
What you have first calculates the expression "sin" || "cos" || "tan"
and then tries to compare the string with that.
But, in fact, it's not really necessary to have this two-step process. You can simply do something like this:
if (function == "sin") {
std::cin >> input;
std::cout << "The sine is " << sin (input) << std::endl;
system ("PAUSE");
} else if (function == "cos") {
std::cin >> input;
std::cout << "The cosine is " << cos (input) << std::endl;
system ("PAUSE");
} else if (function == "tan") {
std::cin >> input;
std::cout << "The tangent is " << tan (input) << std::endl;
system ("PAUSE");
} else {
// It's neither sin, cos nor tan if you get here.
firstnumber = ::atof (function.c_str ());
// and the rest of your stuff in here.
}