Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带对数的Delta V计算器问题 我试图创建一个程序来计算我的KalBar空间程序游戏,而C++(在Eclipse IDE中运行)似乎相信我试图调用“LoC()”函数实际上是指引用未创建的函数。我非常感谢在这件事上的任何帮助 #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); } } #包括 #包括 使用名称空间std; int main(){ cout_C++_Logarithm - Fatal编程技术网

带对数的Delta V计算器问题 我试图创建一个程序来计算我的KalBar空间程序游戏,而C++(在Eclipse IDE中运行)似乎相信我试图调用“LoC()”函数实际上是指引用未创建的函数。我非常感谢在这件事上的任何帮助 #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); } } #包括 #包括 使用名称空间std; int main(){ cout

带对数的Delta V计算器问题 我试图创建一个程序来计算我的KalBar空间程序游戏,而C++(在Eclipse IDE中运行)似乎相信我试图调用“LoC()”函数实际上是指引用未创建的函数。我非常感谢在这件事上的任何帮助 #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); } } #包括 #包括 使用名称空间std; int main(){ cout,c++,logarithm,C++,Logarithm,使用数学函数时,可能需要在数学库中链接 这通常是通过在编译命令中添加一个-lm选项来完成的。我认为对于您的计算,您希望使用double(我在这里更喜欢)或float变量。现在,所有小数位都会像整数除法一样被截断。同样,您的循环也不会执行多个迭代,因为退出(0);被调用,终止整个程序。将其删除并退出主函数,返回0;。由于没有日志(int),因此会出现错误消息在cmath中。这也可以通过使用double来解决。如果出现链接器错误,请添加链接器选项-lm请更新您的问题以显示准确的错误消息(复制并粘贴它

使用数学函数时,可能需要在数学库中链接


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

我认为对于您的计算,您希望使用
double
(我在这里更喜欢)或
float
变量。现在,所有小数位都会像整数除法一样被截断。同样,您的循环也不会执行多个迭代,因为
退出(0);
被调用,终止整个程序。将其删除并退出主函数,返回0;。由于没有
日志(int),因此会出现错误消息
cmath
中。这也可以通过使用
double
来解决。如果出现链接器错误,请添加链接器选项
-lm

请更新您的问题以显示准确的错误消息(复制并粘贴它,不要重新键入或汇总)
std::log
函数接受并返回一个
double
。您正在向它输入一个
int
,并希望返回一个
int
log(int)
的问题不是可以通过通常的数字升级自动解决吗?