Thank you both, my question is solved, but things you have learned me created some other questions for me:
1-Codewalker, you said if I change the char to unsigned char or int, it's going to end an infinite loop, why?
2-TheIdeasMan, you said there is no need for long double. I thought long double is more precise than double!!! (and I wanted a more precise answer) Am I wrong? By the way, what is the difference between Double and Long double? (I have read the part "Variables. Data Types" but I didn't mention such a thing about their difference)
3-TheIdeasMan, you were right, the GOTO was an evil and it didn't work correctly, instead I sued a WHILE loop and it's working fine. Why is GOTO not working?
And Finally I put the code I changed, Please check if there is anything that you can learn me more. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
using namespace std;
int main ()
{
double x;double sin;signed char sign;unsigned char k;double y;double enterance;
cout<<"Please enter the angle you want me to calculate it's sine or enter ''123456789'' to exit (in Radian):\n";
cin>>x;
while (x!=123456789)
{
sin=x;y=x*x;sign=(-1);k=3;
for (k=3;k<252;k=k+2)
{
sin=sin+(sign*y)/(k*(k-1));
sign=((-1)*sign);
}
cout<<sin;
cout<<"\nPlease enter another angle or enter ''123456789'' to exit:";
cin>>x;
}
return 0;
}
|
And about the Documentation, it is my source for learning and I have read the Control Structures before, but as my native language is not English, It was a little confusing for me, But now I know Exactly how FOR loop works.
Thanks again!
(sorry if it is too long)