我正在尝试创建一个程序来计算我的 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/