2013-04-04 5 views
1

저는 한 달 전에이 C++ 과정을 시작했습니다. 이제 이것을 계산하는 프로그램을 작성했습니다. 내가 뭘 잘못했는지 모르겠다.정답을주지 않는 C++ (함수, 코사인)

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

float gatherl1(); 
float gatherl2(); 
float gatheran(); 
void values(float,float,float); 
float findlength(float,float,float); 
float findan2(float,float,float); 
float findan3(float,float,float); 
void name(float,float,float); 


int main(void) 
{ 
    float length1,length2; 

    float length3; 

    float angle1,angle2,angle3; 

    length1 = gatherl1(); 
    length2 = gatherl2(); 
    angle1 = gatheran(); 

    values(length1,length2,angle1); 

    length3 = findlength(length1,length2,angle1); 

    angle2 = findan2(length1,length2,length3); 
    angle3 = findan3(length1,length2,length3); 

    name(angle1,angle2,angle3); 
} 

float gatherl1() 
{ 
     float l1; 

     printf("Enter the length of one of the sides of any triangle\n"); 

     scanf("%f",&l1); 

     return l1; 
} 

float gatherl2() 
{ 
     float l2; 


     printf("Enter the length of the other side\n"); 

     scanf("%f",&l2); 



     return l2; 
} 

float gatheran() 
{ 
     float angle; 

     printf("Enter the angle between them.\n"); 

     scanf("%f",&angle); 

     return angle; 
} 



void values(float l1, float l2, float angle) 
{ 
    printf("\n The two sides are %f and %f. The angle between them is %f \n",l1,l2,angle); 
} 
float findlength(float l1, float l2, float angle) 
{ 
    float l3,pyt,boy; 

    if (angle==90) 
    { 
     pyt = pow(l1,2) + pow(l2,2); 
     l3 = sqrt(pyt); 

    } 
    else 
    { 
     boy = pow(l1,2) + pow(l2,2) - 2*l1*l2*cos(angle); 
     l3 = sqrt(boy); 
    } 


    printf("\nthe third side is = %f",l3); 
    return l3; 
} 

float findan2(float l1, float l2, float l3) 
{ 
    float cosangle2,angle2; 

    cosangle2 = (pow(l2,2) + pow(l3,2) - pow(l1,2))/(2*l2*l3); 
    angle2 = acos(cosangle2); 
    return angle2; 

} 
float findan3(float l1, float l2, float l3) 
{ 
    float cosangle3,angle3; 

    cosangle3 = (pow(l1,2) + pow(l3,2) - pow(l2,2))/(2*l1*l3); 
    angle3 = acos(cosangle3); 
    return angle3; 

} 

void name(angle,angle2,angle3) 
{ 
    printf("\n\n\n the other two angles are %f and %f",angle2,angle3); 

    printf("\n\n\n The angle you put is %f",angle); 


    if(angle == 90) 
    { 
     printf("\n The triangle is a right triangle\n"); 
    } 
    else if(angle < 90) 
    { 
     printf("\n The triangle is a acute triangle\n"); 
    } 
    else 
    { 
     printf("\n The triangle is a obtuse triangle\n"); 
    } 


} 

나는 cos와 arccos 기능을 사용하지 않으므로 그 이유가 확실하지 않습니다. 또는 함수이기 때문에 함수이기도합니다. 제발 도와주세요 !! 고맙습니다.

+4

정사각형을 계산하려면 실제로''pow''가 필요합니까? – gongzhitaao

답변

4

라디안 단위로 함수에 전달한 값입니까? 왜냐하면 cos과 arccos는 라디안을 입력으로 가정하기 때문입니다.

+2

단지 질질 거리기 쉽지만,'acos'의 경우에는 입력이 아니라 출력입니다. – Barmar

+0

잡기에 감사드립니다. – Fred

1

C 삼각 함수는 각도가 아닌 라디안 단위로 작동합니다. 각도를 라디안으로 변환하려면 pi/180을 곱해야합니다.