2 Replies - 1396 Views - Last Post: 05 May 2014 - 06:39 PM Rate Topic: -----

#1 SeaDiver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-May 14

Need help with Right Triangle Program

Posted 05 May 2014 - 06:27 PM

I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514. Dunno what the issue is.

#include <stdio.h>
#include <math.h>

main()
{
	float angle;
	float hypotenuse;
	float adjacent;
	float opposite;

	puts("This program will compute the length of the opposite and adjacent");
	puts("sides of a right triangle, given the length of the hypotenuse and");
	puts("an angle.");
	puts("");

	printf("Please input an angle of the triangle. => ");
	scanf("%f", &angle);
	printf("Please input the length of the hypotenuse. => ");
	scanf("%f", &hypotenuse);
	puts("");

	opposite = sin(angle) * hypotenuse;
	adjacent = cos(angle) * hypotenuse;

	printf("The length of the opposite side is %f units. \n", opposite);
	printf("The length of the adjacent side is %f units. \n", adjacent);
}
	


This post has been edited by jimblumberg: 05 May 2014 - 07:31 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with Right Triangle Program

#2 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6380
  • View blog
  • Posts: 25,776
  • Joined: 12-December 12

Re: Need help with Right Triangle Program

Posted 05 May 2014 - 06:35 PM

You are working in degrees but the computer is working in radians.
Was This Post Helpful? 1
  • +
  • -

#3 SeaDiver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-May 14

Re: Need help with Right Triangle Program

Posted 05 May 2014 - 06:39 PM

Ohhhh, that makes much more sense. Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1