[英]Delta V Calculator issue with Logarithms
我正在嘗試創建一個程序來為我的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
選項來完成此操作。
我認為,對於您的計算,您想使用double
(在這里我更喜歡)或float
變量。 現在,當您進行整數除法時,所有小數位都會被截斷。 同樣,您的循環最多只能進行一次迭代,例如exit(0);
被稱為終止整個程序。 刪除它並return 0;
退出您的主函數return 0;
。 發生您的錯誤消息是因為cmath
沒有log(int)
。 這也可以通過使用double
解決。 如果出現鏈接器錯誤,請附加鏈接器選項-lm
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.