Hello,

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.

#include <iostream>

#include <math.h>

#define pi 3.14159265

using namespace std;

int main()

{

double z1, z2, a;

a=-0.13;

cout << "a: -0.13 " << endl;

z1=2*(sin(3*pi-2*a)*sin(3*pi-2*a))*(cos(5*pi+2*a)*cos(5*pi+2*a));

cout << "z1 = " << z1 << endl;

z2=1/4-1/4*sin(5/2*pi-8*a);

cout << "z2 = " << z2 << endl;

return 0;

}

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.

#include <iostream>

#include <math.h>

#define pi 3.14159265

using namespace std;

int main()

{

double z1, z2, a;

a=-0.13;

cout << "a: -0.13 " << endl;

z1=2*(sin(3*pi-2*a)*sin(3*pi-2*a))*(cos(5*pi+2*a)*cos(5*pi+2*a));

cout << "z1 = " << z1 << endl;

z2=1/4-1/4*sin(5/2*pi-8*a);

cout << "z2 = " << z2 << endl;

return 0;

}

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?

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?

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 :)

enjoy programming :)

Topic archived. No new replies allowed.