我是C ++语言的新手,我正在尝试创建一个程序,它将输出sin,cos和tangent的所有值。该表假设在使用for循环时以10为增量执行值0到360。我一直在我的for循环中得到非停止错误,并且想知道是否有人能告诉我我做错了什么。任何和所有建议都表示赞赏。
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double x, r;
double sin(x), cos(x), tan(x);
double PI = 3.1415926;
for (x = 0:10:360)
r= x * PI /180.0;
cout << "The sin of:" << x << "is:" <<sin(r) << "\n" << endl;
cout << "The cos of:" << x << "is:" <<cos(r) << "\n" << endl;
cout << "The tan of:" << x << "is:" <<sin(r)/cos(r) << "\n" << endl;
return 0;
}
答案 0 :(得分:4)
您的for
循环语法错误,并且您缺少一些大括号 - 请尝试:
for (x = 0.0; x < 360.0; x += 10.0)
{
r = x * PI / 180.0;
cout << "The sin of: " << x << " is: " << sin(r) << endl;
cout << "The cos of: " << x << " is: " << cos(r) << endl;
cout << "The tan of: " << x << " is: " << tan(r) << endl;
}