好吧,所以我必须使用if-else语句来创建一个程序,以便计算输入的数字的正弦,如果它是奇数,或者计算cos如果是偶数,则为数字。我的程序一直失败,我不知道为什么。有人可以给我一个小费,请问我做错了什么?使用if-else语句计算sin和cos的C++
这是我到目前为止所(我的程序不断失败,所以我不知道下一步该怎么做,直到我解决这个问题)
#include<iostream>
#include<cmath>
using namespace std;
void main()
{
const double pi = 3.1415926535897932384626433832795;
int a;
cout << "Please type in a 2 digit number : " << endl;
cin >> a;
if(a % 2 == 0)
{
cout << "The input is" << a << "It is an even number." << endl;
cout << cos(a) << endl;
}
else
{
cout << "The input is" << a << "It is an odd number." << endl;
cout << sin(a) << endl;
}
} // main
'我的程序保持失败',用什么方式**失败?我没有看到明显的错误。为什么我们不得不一直问这个我不知道。 – john
@john我如何找出失败的方式? –
也许你正在进入学位课程? C++ sin/cos期望弧度 – BeniBela