Since there are no questionmarks, I assume the question is "How do you write a C++ program that solves this equation?"
C++ is a programming language and by itself is not able to solve your equation, i.e. C++ won't do any transformation to your equation to get it into a form where y
occurs only on the lefthand side and all parameters on the righthand side. You have to transform it yourself, manually or by using a solver.
What happens in the posted code?
Lets start at the leftmost part of the equation y/(double)(3/17)
from inside out according to the parentheses:
3/17
is interpreted as integer division, which results in 0
;
(double)(0)
casts the integer 0
into a double of 0.0
;
y/0.0
is a division by 0 as explained in this post which results in your error.
You could fix this as pointed out in the comments by either casting the first integer like (double)3/17
or turning the integer 3
into a double 3.0
or using static_cast
.
- However,
y
is still initialized to 0, so y/(double)3/17
is 0
and the equation calculated is basically -z + x/(a%2) + PI
.
So, unless you transform the equation and put the transformed equation into the code, you won't get the results you expect.