#include<iostream>
#include<cmath>
usingnamespace std;
int main (){
cout<<"Hello, welcome to xxxx trig. calculator"<<endl;
cout<<"enter 1 for tan, enter 2 for sin, enter 3 for cos"<<endl;
int select;
cin>>select;
do{ double a;
cout<<"length of one side"<<endl;
cin>>a;
double b;
cout<<"enter angle"<<endl;
cin>>b;
double radian=(b*3.14159/180);
double unknownS=tan(radian)*a;
cout<<"unknown length"<<unknownS<<endl;
}
while(select=='1');
do{
double a;
cout<<"length of one side"<<endl;
cin>>a;
double b;
cout<<"enter angle"<<endl;
cin>>b;
double radian=(b*3.14159/180);
double unknownS=sin(radian)*a;
cout<<"unknown length"<<unknownS<<endl;
}
while(select=='2');
do{
double a;
cout<<"length of one side"<<endl;
cin>>a;
double b;
cout<<"enter angle"<<endl;
cin>>b;
double radian=(b*3.14159/180);
double unknownS=cos(radian)*a;
cout<<"unknown length"<<unknownS<<endl;
}
while(select=='3');
return 0;
}
My problem is that I want the user to choose sin, tan or cos by entering 1,2, or 3, but my code isn't allowing me to do that. It is outputting everything. I am wondering if there is a way to fix this problem. Thanks very much for your time.
it looks like you to calculate a tangent value, if the user enters 1; calculate a sine value, if the user enters 2; and calculate a cosine value, if the user enters 3.
Also, as select is an int, this
select=='1'
is comparing select against the ascii code value for the character '1', which is 49 in decimal.
ok vlad from moscow, i'm now looking at the date you posted your comment, and the date i edited mine (the one right before it).
looks like you commented right before i submitted my edit.
i think you didn't read the edit.
anyway, after i read yours, i went to my C++ compiler and pasted that code in it, and tried the program myself.
it works like charm.
don't take it hard on me, i felt like my first contribution was discarded, that's why i posted the second.