Hello everyone, I am trying to build a simple derivative 'calculator' that takes a string (sinx, cosx, etc...) and outputs what the derivative of the simple trig function is. When I compile and run it it doesn't output anything other than invalid input no matter the input. Any help would be appreciated!
#include <iostream>
#include <string>
using namespace std;
int main(){
string function;
cout<<"Please enter a basic trigonometric function (secx, sinx, tanx, etc...): ";
cin>>function;
cout<<"The function is: "<<function<<endl;
calculate(function);
return 0;
}
void calculate(string function){
if(function==sinx){
cout<<"The derivative of "<<function<<"is cosx!";
}
else if(function==cosx){
cout<<"The derivative of "<<function<<"is -sinx!";
}
else if(function==tanx){
cout<<"The derivative of "<<function<<"is sec^2x!";
}
else if(function==secx){
cout<<"The derivative of "<<function<<"is secxtanx!";
}
else if(function==cscx){
cout<<"The derivative of "<<function<<"is -cscxcotx!";
}
else if(function==cotx){
cout<<"The derivative of "<<function<<"is -csc^2x!";
}
else{
cout<<"Invalid input!";
}
}
Thank you guys for the speedy responses. I realize now that the problem I had was that the if statements did not have the quotation marks around the value. There was no need for the trigonometric string variables when you take this into account. Again, thank you guys very much.