I am attempting to calculate the Sine function of an angle entered by the user in radians. I need to print the value within a given tolerance as well. I have spent a lot of time and am making very little progress. Any help would be greatly appreciated! Thanks! My main issue is a returning a value within the given tolerance.
// Tolerance is an epsilon value ex. .00001
public static void sineCalc(double angle, double tolerance) {
int power = 1;
double currentAnswer = 0.0;
int count = 0;
double answer = 0.0;
double difference = 0.0;
int i = 1;
while (difference > tolerance || difference == 0) {
if (i % 2 == 0) {
currentAnswer = -Math.pow(angle, power) / getfactorial(power);
} else {
currentAnswer = Math.pow(angle, power) / getfactorial(power);
}
answer = answer + currentAnswer;
power = power + 2;
difference = Math.sin(angle) - answer;
difference = Math.abs(difference);
count++;
i++;
}
System.out.println(answer);
}