1

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;

}
4

2 回答 2

2
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)

(这是范围的正确公式)

于 2013-05-20T00:10:01.347 回答
0

您定义angle为双精度,因此您不想通过编写*angle. pow()接受两个参数,所以你可能想写pow(velocity,2). sin(angle)*pow(velocity,2)应该管用。我建议您,因为如果您只想计算,则sin(angle)*velocity*velocity不需要使用。pow(x,2)x*x

哦,请注意代码中的重力为 0.0,因为它被定义为velocity*9.8速度为 0.0。

于 2013-05-20T00:09:26.433 回答