c++ - Delta V 计算器问题与对数

标签 c++ logarithm

我正在尝试创建一个程序来计算我的 Kerbal Space Program 游戏的 Delta-V,而 C++(在 Eclipse IDE 中运行)似乎认为我尝试调用“log()”函数是实际上我引用了一个未创建的函数。我非常感谢任何帮助!

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    cout << "Hello. Welcome to the Kerbal Space Program Delta V Calculator. \n";
    cout << " \n";
    cout << "Note that each stage must use the same engine for this calculator.";
    cout << "\n";
    cout << "\nHow many stages make up your rocket? :";
    int stageNumber;
    cin >> stageNumber;
    //cout << "Your rocket has " << stageNumber << " stages.\n";
    cout << "\n\nStart from the bottom stage, please. ";
    //ACTUAL DELTA V CALCULATIONS
    for(int currentStage = 1; currentStage <= stageNumber; currentStage = currentStage + 1){
        cout << "What is the total mass of this stage? :";
        int totalMass;
        cin >> totalMass;
        cout << "What is the fuel mass of this stage? :";
        int fuelMass;
        cin >> fuelMass;
        cout << "\n";
        int dryMass;
        dryMass = totalMass - fuelMass;
        cout << "Your dry mass is" << dryMass << "\n";
        cout << "\n";
        cout << "Give the specific impulse of this stage's engine. \n";
        int iSP;
        cin >> iSP;
        cout << "Here is the Delta V of your rocket.\n";
        int deltaMass;
        deltaMass = totalMass/dryMass;
        int deltaV;
        deltaV = iSP * log(deltaMass);
        cout << deltaV;

        exit(0);
    }

}

最佳答案

使用数学函数时,您可能需要链接数学库。

这通常是通过在编译命令中添加一个-lm选项来完成的。

关于c++ - Delta V 计算器问题与对数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25515195/

相关文章:

c++ - 算术序列 - 检查

c++ - 为什么一个函数接受一个空指针?

python - 值错误 : math domain error

algorithm - 深度快速排序的复杂性

python - 使用 Python C API 时奇怪的内存行为

c++ - 将位移动到掩码中给定位置的快速方法

python - 在 Matplotlib 中将文本旋转到对数刻度上的一条线上

sse - SSE的对数,还是切换到FPU?

Python - 如何将列表转换为日志(列表)

c++ - 为什么我不能使用继承来实现C++中的接口(interface)?