Conversion Euro Gas to US Gas

nothingasis

In Runtime
Messages
198
Location
CA
I have a formula that I'm trying to use to convert European gas consumption to U.S. gas consumption. When I punch it in the calculator I get the right answer but when i punch it into the computer it gives me a hex number. Is there a syntax error that I'm not catching or what do you guys think the problem is?

Btw:
12.41 liters / 100 km = 19 mi / g

#include <iostream>

using namespace std;

/*
Prototypes
*/
double convertToMPG(double);

/*
Main() Code
*/
int main()
{
cout << "Enter the number of liters per 100 km: ";
double liters;
cin >> liters;
convertToMPG(liters);
cout << liters << " liters/100km is " << convertToMPG << " mpg." << endl;
system ("pause");
return 0;

}
/*
function code
*/

double convertToMPG(double convertLiters)
{
double mpg;
mpg = .2641721;
mpg = mpg * convertLiters;
mpg = 62.14 / mpg;
return mpg;
}

Please and thank you!
 
Code:
convertToMPG(liters);
cout << liters << " liters/100km is " << convertToMPG << " mpg." << endl;

Your problem lies in those 2 lines. convertToMPG(liters) returns a double. You're not doing anything with that return.. You need to either store it in a variable, or call it inside the cout stream.

I.e.
Either this:
Code:
someVariable = convertToMPG(liters);
cout << liters << " liters/100km is " << convertToMPG << " mpg." << endl;

or in a single line:
Code:
cout << liters << " liters/100km is " << convertToMPG(liters) << " mpg." << endl;

The reason it's giving you a hex number (for me it's outputting 1 always when I ran it), is because it's grabbing the chunk of memory that call is located in, and printing the memory location (the pointer to the call... not sure if you've learned about pointers in C++ yet or not). Memory is stored as hex numbers...hence the hex output.
 
i actually just caught onto pointers while watching some other video talk about pointers indirectly. But I figured that was the reason its giving me a hex as i was trying to figure out the problem in my dream from last nught. u just made my dream come true haha lol thanks
 
Back
Top Bottom