I want to write a code that finds the derivative to any function and want to take a user input on what type of function they're inputting is. Essentially I tried to write a while loop that only accept valid answers but the while loop isn't behaving as intended. Here is my code:
int main()
{
std::cout << "Welcome to the differentiation calculator: ";
std::cout << std::endl;
std::cout << "Please input what type of function you have: Algebraic,Trigonometric,Exponential, Hyperbolic : " << std::endl;
std::string UsersTypeOfFunction;
std::cin >> UsersTypeOfFunction;
while (UsersTypeOfFunction != "Hyperbolic" || UsersTypeOfFunction != "hyperbolic" || UsersTypeOfFunction != "Exponential" || UsersTypeOfFunction != "exponential" || UsersTypeOfFunction != "Trigonometric" || UsersTypeOfFunction != "trigonometric" || UsersTypeOfFunction != "Algebraic " || UsersTypeOfFunction != "algebraic")
{
std::cout << "Please input a Valid function type. ";
std::cin >> UsersTypeOfFunction;
}
return 0;
}
if my code is the issue please let me know
while (UsersTypeOfFunction != "Hyperbolic" || UsersTypeOfFunction != "hyperbolic"- if the value of the variable isHyperbolic, then the second part of this condition will still be true, because the value is nothyperbolic; and since you joined all those individual conditions via OR, the whole thing is also still true. You want to continue your loop while the variable does not have the first value, and not the second one, and ...||with&&a lot. There are probably a dozen duplicates to this question, but I'm not sure how to search for them.std::transform,std::tolower, andstd::toupper.std::endldoes. Use'\n'to end a line unless you have a good reason not to.