我只是在VS Community 2017中弄乱了,每当我调试时,答案输出如下。这是在我调试过的两个不同程序中发生的。
前任。输出为00F911D1,而不是预期值
该值似乎随每个输出而变化。当我在另一个系统上运行该代码时,按预期方式工作。这是我运行的结束于此特定输出的代码:
#include <iostream>
#include <iomanip>
using namespace std;
double gasPrice;
int avgMPG;
int tankSize;
double CPM()
{
double math;
math = (gasPrice * tankSize) / avgMPG;
return math;
}
int main()
{
cout << setprecision(2);
cout << "Please enter the cost of gas without currency => ";
cin >> gasPrice;
cout << "Enter the size of your fuel tank to the nearest whole number => ";
cin >> tankSize;
cout << "Enter your average miles per gallon as a whole number => ";
cin >> avgMPG;
cout << "Your cost per mile is: " << CPM << endl;
system("pause");
return 0;
}
我能找到的与此问题有关的唯一信息是禁用十六进制输出,但据我所知,我的是。
我不确定这是否可以解决您的问题,但在调用函数时应在括号中加上括号。对于您的示例,请尝试使用CPM()
而不是CPM
:
#include <iostream>
#include <iomanip>
using namespace std;
double gasPrice;
int avgMPG;
int tankSize;
double CPM()
{
double math;
math = (gasPrice * tankSize) / avgMPG;
return math;
}
int main()
{
cout << setprecision(2);
cout << "Please enter the cost of gas without currency => ";
cin >> gasPrice;
cout << "Enter the size of your fuel tank to the nearest whole number => ";
cin >> tankSize;
cout << "Enter your average miles per gallon as a whole number => ";
cin >> avgMPG;
cout << "Your cost per mile is: " << CPM() << endl;
system("pause");
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句