### Trigonometry

Hi, I am trying to make a trig calculator.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include using namespace std; int main (){ cout<<"Hello, welcome to xxxx trig. calculator"<>select; do{ double a; cout<<"length of one side"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=tan(radian)*a; cout<<"unknown length"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=sin(radian)*a; cout<<"unknown length"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=cos(radian)*a; cout<<"unknown length"<

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.
Last edited on
The code you showed shall not be compiled. So iat least try to write code that is compiled without errors.
do not use do-while loops, you need a normal while loop for this problem.
sorry, i forgot one of the do{
The condition in the do-while loop is incorrect

while(select=='1');

You are entering an integer number form 1 to 3 inclusively but trying to compare it with character '1'.

I think you meant

while( select < 1 || select > 3 );
Going by the instuctions you display

 `enter 1 for tan, enter 2 for sin, enter 3 for cos`

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.

Andy

Last edited on
try this:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include #include using namespace std; int main (){ cout<<"Hello, welcome to xxxx trig. calculator"<>select; while(select=='1'){ double a; cout<<"length of one side"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=tan(radian)*a; cout<<"unknown length"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=sin(radian)*a; cout<<"unknown length"<>a; double b; cout<<"enter angle"<>b; double radian=(b*3.14159/180); double unknownS=cos(radian)*a; cout<<"unknown length"<

anyway, this still is a lame way to keep the choice repeating.

edit: i changed select from int to char
Last edited on
 @Rechard3

i did read the other posts, i still don't know which one you're talking about !!!
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.
Topic archived. No new replies allowed.