For my lab, I am trying to print out the value of sine using a function. The printed value should display 5 digits after the decimal. However, the angle that is being used is also printing out 5 digits. For example, it prints out like sin(45.00000) when I want it to look like sin(45). I think it has something to do with the first bit of code in int main(). Can someone help?
#include <iostream>
#include <cmath>
constdouble PI = 3.14159;
usingnamespace std;
double degreestoRadians (double Degrees)
{
return (Degrees * 3.14159/180);
}
int drawLine (char c, int numRepetitions) // print out character numRepetitions times
{
int Line;
for (int i = 1; i <= numRepetitions; i++)
cout << '-';
return (Line);
}
int main ()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(5); // show five digits to the right of decimal
double valueOfSine;
double angle;
char Line;
for (int i = 0; i <= 360; i += 5)
{
angle = i;
valueOfSine = degreestoRadians(angle); // calling function degreestoRadians in main
cout << "sin("<< angle <<") = " << sin(valueOfSine) << endl;
if ((angle == 0) || (angle == 90) || (angle == 180) || (angle == 270) || (angle == 360))
{
Line = drawLine('-', 30); // calling function drawLine in main
cout << endl;
}
}
return 0;
}