[英]Error in job Build for constructing C++ program to determine range
I was till was experiencing some issues until i made the change to my formula for gravity. 直到我改变重力公式之前,我一直遇到一些问题。 all is working now.
现在一切正常。 thanks everyone.
感谢大家。 I appreciate all the great feedback
感谢所有的宝贵意见
#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);
This is not valid C++. 这不是有效的C ++。
pow
is a function that takes two arguments. pow
是一个带有两个参数的函数。 x^y would be represented as pow(x, y)
. x ^ y将表示为
pow(x, y)
。
Also, sin(*angle)
is invalid as angle
is neither a pointer nor a class with a defined *
operator. 另外,
sin(*angle)
无效,因为angle
既不是指针也不是具有定义的*
运算符的类。
I think this is what you're looking for: 我认为这是您要寻找的:
range = sin(2 * angle) * velocity * velocity / gravity;
// (No need to use pow(velocity, 2) over velocity * velocity)
(This is the correct formula for range) (这是范围的正确公式)
You defined angle
as a double, so you don't want to dereference it by writing *angle
. 您将
angle
定义为double,因此您不想通过编写*angle
取消引用它。 pow()
takes two arguments, so you probably want to write pow(velocity,2)
. pow()
有两个参数,因此您可能要编写pow(velocity,2)
。 sin(angle)*pow(velocity,2)
should work. sin(angle)*pow(velocity,2)
应该起作用。 I'd recommend sin(angle)*velocity*velocity
, as you don't need to use pow(x,2)
if you only want to calculate x*x
. 我建议使用
sin(angle)*velocity*velocity
,因为如果只想计算x*x
pow(x,2)
不需要使用pow(x,2)
。
Oh, and note that gravity is 0.0 in your code, as it is defined as velocity*9.8
while velocity is 0.0. 哦,请注意,您的代码中的重力为0.0,因为它的定义为
velocity*9.8
而速度为0.0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.