0

Hi all,
Now, I'm trying practice on c++ basics, since few minutes I tried practice "library functions" especially "sin" function, I wrote this trivial program to calculate angle in console screen, but when I input 90 degree it gave me 0.8939, but with calculator it gave me 1, why console can not gave my integer answer like calculator..?

This is my code:

//calculate sin angle | library functions
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double angle, answer;

	cout << "Enter Angle: ";
	cin  >> angle;
	answer = sin(angle);
	cout << "sin " << angle << " is = " << answer << endl;

	return 0;
}
3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Stefano Mtangoo
0
#include <iostream>
#include <cmath>

using namespace std;
#define PI 3.14

int main(){	

	 
	 //calculate sin angle | library functions
	double angle, angle_rad, answer;

	cout << "Enter Angle in degrees: ";
	cin  >> angle;
	angle_rad = PI*angle/180;
	answer = sin(angle_rad);
	cout << "sin " << angle << " is = " << answer << endl;
	cin.get();
	return 0;
	
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.