问题:在做计算三角函数的时候,出现无法跳出循环的问题(ps:希望能在原有的代码上改正)
代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.1415926
#define CLEAR "cls"
void TriangleMenu()
{
system(CLEAR);
printf("**************三角函数计算***************\n");
printf("*\t\t1.求正弦值\t\t*\n");
printf("*\t\t2.求余弦值\t\t*\n");
printf("*\t\t3.求正切值\t\t*\n");
printf("*\t\t4.返回上一级\t\t*\n");
printf("*****************************************\n");
}
double Triangle()
{
double x,result,rad;
int choice;
printf("请输入选择:\n");
scanf("%d",&choice);
printf("请输入x的值:\n");
scanf("%lf",&x);
switch(choice){
case 1:Triangle(x);
rad=x*(PI/180);
result=sin(rad);
printf("sin x=%lf\n",result);
break;
case 2:Triangle(x);
result=cos(rad);
rad=x*(PI/180);
printf("cos x=%lf\n",result);
break;
case 3:Triangle(x);
rad=x*(PI/180);
result=tan(rad);
printf("tan x=%lf\n",result);
break;
case 4:return 0;
default:printf("请重新输入!");
break;
}
return x;
}
int main()
{
double x;
TriangleMenu();
Triangle(x);
return 0;
}
出现问题截图: