0

I'm just messing around in VS Community 2017 and whenever I debug, the answer is output as below. This happens in two different programs I've debugged.

ex. Output is 00F911D1 rather than expected value

Output of code is 00F911D1 rather than expected value.

This value seems to change with each output. When I run this on another system the code works as expected. Here's the code that I ran that ended in this specific output:

#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;

}

The only information I can find related to this issue is disabling hex output but from what I can tell, mine is.

0

I am not certain if this will solve your problem, but you should include parentheses when calling a function. For your example, try using CPM() instead of 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;

} 
| improve this answer | |
  • 1
    This is correct. Not using the parentheses means you are printing the address of that function in memory, because you are using a pointer. Using them means you are printing the return value of the function in question. – TuxStash.de Sep 18 '19 at 18:18
  • Thanks for your reply. I made some edits to the code that overall reflected your comments. It was a similar conclusion about the memory that I came to shortly after. Again, thanks! – ajaxburger Sep 18 '19 at 18:39
  • No problem. Glad you got it solved. =) – Anaksunaman Sep 18 '19 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.