C++ Conversion
I can not get this program to work at all. The answer always comes out 0 to me.
Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles traveled by the car and will then output the number of miles per galloon the car delivered.
[php]#include
#include
int main()
{
double liters,gallons, miles, gal_per_mile;
cout << "Enter the number of liters you input into your car\n";
cout << "Before your next fill up.\n";
cin >> liters;
cout << "Now enter the number of miles you have driven before\n";
cout << "your next fill up.\n";
cin >> miles;
gallons=liters*0.264179;
gal_per_mile=gallons/miles;
cout << "Your car runs";
cout << gal_per_mile;
cout << "gallons per mile.\n";
system("PAUSE");
return 0;
}
[/php]
Thanks guys. This means a lot to me. :bigggrin:
Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles traveled by the car and will then output the number of miles per galloon the car delivered.
[php]#include
#include
int main()
{
double liters,gallons, miles, gal_per_mile;
cout << "Enter the number of liters you input into your car\n";
cout << "Before your next fill up.\n";
cin >> liters;
cout << "Now enter the number of miles you have driven before\n";
cout << "your next fill up.\n";
cin >> miles;
gallons=liters*0.264179;
gal_per_mile=gallons/miles;
cout << "Your car runs";
cout << gal_per_mile;
cout << "gallons per mile.\n";
system("PAUSE");
return 0;
}
[/php]
Thanks guys. This means a lot to me. :bigggrin:
0
Comments
Second: you're multiplying by 0.26... and gallons is an int. so you're really doing: floor(liters * 0.26...). And then you're dividing that by what I assume is a large number, so your calculation is: floor(floor(litres * .26...)/miles). Which is likely zero, unless litres is huge and miles is small.