a problem with sin calculation.

#include <iostream.h>
#include <math.h>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
const float PI=3.1415926536;
int cnt,fct,z;
float x,y,fnl;
char f1Name[40]; //filename
ofstream f1;
cout<<"enter the file name for writing:";
cin>>f1Name;
f1.open(f1Name);
if(f1.fail())
{
cout<<"the file cannot be opened";
exit(1);
}else
cout<<"file opened successfully.";
for(z=0;z<=360;z+=5)
{
if(z%180!=0) // i wrote that due to a false calculation as a bypass
{
x=z;
x*=(PI/180);
y=x;
fct=1;
for(cnt=1;cnt<100;cnt++)
{
fnl+=y;
fct+=1;
y/=fct;
fct+=1;
y/=fct;
y*=(-1*pow(x,2));
}
cout<<x<<" "<<"sin"<<z<<"="<<fnl<<endl;
f1<<x<<" "<<z<<" "<<fnl<<endl;
fnl=0;
}else
{
cout<<x<<" "<<"sin"<<z<<"=0"<<endl;
f1<<x<<" "<<z<<" "<<"0"<<endl;
}
}
f1.close();
cout<<"file proccess ended.";
getch();
return 0;
}

all seems fine, but here is the results of the file: (exe results are the same, the problem is numbers in calculation i think,and dont know exactly where it is.)

3.21396e-039 0 0 (i changed the code a bit, but the first number is still wrong)
0.0872665 5 0.0871557
0.174533 10 0.173648
0.261799 15 0.258819
0.349066 20 0.34202
0.436332 25 0.422618
0.523599 30 0.5
0.610865 35 0.573576
0.698132 40 0.642788
0.785398 45 0.707107
0.872665 50 0.766044
0.959931 55 0.819152
1.0472 60 0.866025
1.13446 65 0.906308
1.22173 70 0.939693
1.309 75 0.965926
1.39626 80 0.984808
1.48353 85 0.996195
1.5708 90 1
1.65806 95 0.996195
1.74533 100 0.984808
1.8326 105 0.965926
1.91986 110 0.939693
2.00713 115 0.906308
2.0944 120 0.866025
2.18166 125 0.819152
2.26893 130 0.766044
2.35619 135 0.707107
2.44346 140 0.642788
2.53073 145 0.573577
2.61799 150 0.5
2.70526 155 0.422618
2.79253 160 0.34202
2.87979 165 0.258819
2.96706 170 0.173648
3.05433 175 0.0871559
3.05433 180 0
3.22886 185 -0.0871561
3.31613 190 -0.173648
3.40339 195 -0.258819
3.49066 200 -0.34202
3.57792 205 -0.422619
3.66519 210 -0.5
3.75246 215 -0.573577
3.83972 220 -0.642787
3.92699 225 -0.707107
4.01426 230 -0.766044
4.10152 235 -0.819153
4.18879 240 -0.866025
4.27606 245 -0.906307
4.36332 250 -0.939692
4.45059 255 -0.965925
4.53786 260 -0.984808
4.62512 265 -0.996195
4.71239 270 -1
4.79966 275 -0.996193
4.88692 280 -0.984807
4.97419 285 -0.965927
5.06145 290 -0.939692
5.14872 295 -0.906307
5.23599 300 -0.866025
5.32325 305 -0.819152
5.41052 310 -0.766045
5.49779 315 -0.707108
5.58505 320 -0.642788
5.67232 325 -0.573575
5.75959 330 -0.499999
5.84685 335 -0.422617
5.93412 340 -0.342018
6.02139 345 -0.258821
6.10865 350 -0.173645
6.19592 355 -0.087159
6.19592 360 0

can some one help with that?
3.21396e-039 that number at the first line (true result must be zero, should i bypass it too :S)
Last edited on
well, i bypassed it and it appears there is nothing wrong with calculation, there is something wrong with something else, i guess. :/ and sorry about my english :P
Last edited on
Topic archived. No new replies allowed.