Oct 4, 2012 at 7:41pm UTC
Variable z2 is not returning the real value, which is the ~z1. The formula is right but somehow it doesnt work, maybe someone could explain why. Many thanks in advance.
#define pi 3.14159265
using namespace std;
double z1, z2, a;
cout << "a: -0.13 " << endl;
cout << "z1 = " << z1 << endl;
cout << "z2 = " << z2 << endl;
Oct 4, 2012 at 8:11pm UTC
what should be the output according to you ? ?
Oct 4, 2012 at 8:50pm UTC
Well, if a=-0.13, then output should be 0.123445. I found a way already. The mistake was in this line: z2=1/4-1/4*sin(5/2*pi-8*a);
I wrote it like z2=0.25-0.25*sin(2.5*pi-8*a);
Maybe you guys know why 1/4 is returned as 0?
Oct 6, 2012 at 5:29pm UTC
the division of an integer with another integer always gives an integer until and unless it is explicitly converted to float. here in this case 1 is an integer, 4 is also an integer. hence the result i.e. 0.25 is converted to integer which turns out to be 0.
enjoy programming :)