Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Whats wrong with my programm

+2 votes
asked Nov 26, 2020 by Евгений Стрельченко (140 points)

I need to solve it,but the solution is -0. 

image

image

1 Answer

+1 vote
answered Nov 27, 2020 by xDELLx (7,630 points)
V=((S/3)*sqrt(S/3.14)*pow(tan(3.14/4-L/2),-3)*pow(tan(L),-1));

Can you try the above,It displays non 0 output.

Also the formula u shared has  tan cubed, but in your code you have used cube root,I thinks its wrong.

I would suggest that you break the individual pow,tan functions & assign them to seperate variables & finally perform the calcualtion on these individual variables.There are associativitey & precedence rules for operators which I find it difficult to always keep them in mind.

eg

double root_S_by_pi = sqrt(S/3.14);
double tanL_by_2= tan(3.14/4-L/2);
..
..
//finally
  V=((S/3)*root_S_by_pi*pow(tanL_by_2,-3)*tan(L));
//V=((S/3)*sqrt(S/3.14)*pow(tan(3.14/4-L/2),-3)*pow(tan(L),-1)); //<--- original code



Also check the sample usage of tan() on this page: https://www.cplusplus.com/reference/cmath/tan/

Specifically note usage of tan :-->

result = tan ( param * PI / 180.0 );

I think thats how the tan () should be invoked.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...