簡體   English   中英

用於構建C ++程序以確定范圍的作業構建中的錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM