[英]Error in job Build for constructing C++ program to determine range
直到我改变重力公式之前,我一直遇到一些问题。 现在一切正常。 感谢大家。 感谢所有的宝贵意见
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
// Initialize objects:
double angle = 0.0;
double velocity = 0.0;
double range = 0.0;
const double PI = 3.141592653589793238;
const double gravity = 9.8; //meters pers second
// Input:
cout << "takeoff angle: ";
cin >> angle;
cout << "Please enter velocity: ";
cin >> velocity;
// Process
angle = angle * PI / 180;
range = sin(2 * angle) * velocity * velocity / gravity;
cout << " range " << range << endl;
system("pause");
return 0;
}
range = sin(* angle)*velocity pow(2);
这不是有效的C ++。
pow
是一个带有两个参数的函数。 x ^ y将表示为pow(x, y)
。
另外, sin(*angle)
无效,因为angle
既不是指针也不是具有定义的*
运算符的类。
我认为这是您要寻找的:
range = sin(2 * angle) * velocity * velocity / gravity;
// (No need to use pow(velocity, 2) over velocity * velocity)
(这是范围的正确公式)
您将angle
定义为double,因此您不想通过编写*angle
取消引用它。 pow()
有两个参数,因此您可能要编写pow(velocity,2)
。 sin(angle)*pow(velocity,2)
应该起作用。 我建议使用sin(angle)*velocity*velocity
,因为如果只想计算x*x
pow(x,2)
不需要使用pow(x,2)
。
哦,请注意,您的代码中的重力为0.0,因为它的定义为velocity*9.8
而速度为0.0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.