hai im new to c++, i have been using microsoft C++ 2008 to compile the codes.
my code is:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int iopt;
string sinx, cosx;
cout << " If you would like to Differentiate/Integrate press '1' or '2'" << endl;
cin>> iopt;
if (iopt==1)
{
cout<< " Enter the variable you would like to Differentiate"<< endl;
if (cin>> sinx)
{
cout<< "cosx"<< endl;
return 0;
}
else if (iopt==2)
{
cout<< "enter the variable ou would like to Integrate"<< endl;
if (cin>> sinx)
{
cout << sinx << " Integrates to -cosx"<< endl;
return 0;
}
else if (cin>> cosx)
{
cout<<cosx<< " Integrates to sinx"<< endl;
return 0;
}
}
else
{
cout<< "You must only choose option '1' or '2' !"<< endl;
exit(99);
}
return 0;
}
this program is for symbolic differentiation and integration for only sinx and cosx!!
but there seems to be a problem, when i execute the code, and choose option 1 , then type sinx it differentiates to cosx; which is fine, however when i choose to type cosx it does not differentiate to -sinx but instead the output i s just cosx o_0, similarly for integration, sinx works but cosx does not integrate to sinx!!! the if anf else if does not seem to make a difference to the strings, so someone please help!!!!! much appreciated!!! thanks
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int iopt;
string x; ////Here modification
cout << " If you would like to Differentiate/Integrate press '1' or '2'" << endl;
cin>> iopt;
if (iopt==1)////and here
{
cout<< " Enter the variable you would like to Differentiate"<< endl;
cin>>x;
if (x=="sinx" )////and here
{
cout<< "cosx"<< endl;
return 0;
}
elseif (x=="cosx")////and here
{
cout<< "-sinx"<< endl;
return 0;
}
}
elseif (iopt==2)////and here
{
cout<< "enter the variable ou would like to Integrate"<< endl;
cin>>x;
if (x=="sinx")////and here
{
cout << "sinx" << " Integrates to -cosx"<< endl;
return 0;
}
elseif (x=="cosx")////and here
{
cout<<"cosx"<< " Integrates to sinx"<< endl;
return 0;
}
}
else
{
cout<< "You must only choose option '1' or '2' !"<< endl;
exit(99);
}
return 0;
}