Visual Studio 2017 以十六进制输出

Visual Studio 2017 以十六进制输出

我只是在 VS Community 2017 中乱搞,每当我调试时,答案都会输出如下。这发生在我调试的两个不同程序中。

例如输出是 00F911D1 而不是预期值

代码的输出是 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;

}

我能找到的与此问题相关的唯一信息是禁用十六进制输出,但据我所知,我的是这样的。

答案1

我不确定这是否能解决您的问题,但调用函数时应该包含括号。例如,尝试使用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;

} 

相关内容