Whenever I type this C++ code segment, i get an answer of 1.32679e-06. Does anyone know why this happens, or how to make the cosine of pi divided by 2 equal zero? It's a radians measurement, not a degrees measurement.

#include <iostream> #include <cmath> using namespace std;

Whenever I type this C++ code segment, i get an answer of 1.32679e-06. Does anyone know why this happens, or how to make the cosine of pi divided by 2 equal zero? It's a radians measurement, not a degrees measurement.

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

const double PI = 3.14159;

cout << "cos(PI / 2) = " << cos(PI / 2) << "\n\n";

return 0;

}

You'll probably never get exactly 0, but you can get much closer (0.0000000000000000612323) by using M_PI as I did here.