#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# trying to debug this program, need help

Member Posts: 15
displays the miles per gallon

#include

using namespace std;

//function prototypes
float getMiles();
float getNumGallons();
int calcMpg(float, float);

int main()
{

float miles = 0.0;
float gallons = 0.0;
float milesPerGal = 0.0;

//enter input items
miles = getMiles();
gallons = getNumGallons();

//calculate miles per gallon
milesPerGal = calcMpg(miles, gallons);

//display output item
cout << fixed;
cout.precision(1);
cout << "Miles per gallon: " << milesPerGal << endl;

return 0;
} //end of main function

//*****program-defined functions*****
float getMiles()
{
cout << "Enter the number of miles: ";
cin >> numMiles;
return numMiles;
} //end of getMiles function

float getNumGallons()
{
float numGallons = 0.0;
cout << "Enter number of gallons: ";
cin >> numGallons;
return numGallons;
} //end of getNumGallons function

float calcMilePG(float distance, float galUsed)
{
float dist / galUsed;
cout << "Enter distance / galUsed: ";
return distance / galUsed;
} //end of calcMpg function

• Member Posts: 127
Hi,

I haven't tested this code. Test it and again, you could make more program-defined functions from this code.

[code]
#include
#include

// Function prototypes
float calcMilePG(float, float);

void main(void)
{
// Declaring the variables
float numMiles;
float numGallons;

// User enters number of miles and gallons
cout << "Enter the number of miles: ";
cin >> numMiles;

cout << "Enter number of gallons: ";
cin >> numGallons;

// Calculates number of miles per gallon
calcMilePG(numMiles, numGallons);

cout << "Miles per gallon: "
<< calcMilePG(numMiles, numGallons) << endl;

system("PAUSE");
}

//*****Program-defined functions*****

float calcMilePG(float numMiles, float numGallons)
{
float MilesPerGallon;
MilesPerGallon = (numMiles/numGallons);
}
[/code]

Hope this helps,

• Member Posts: 3
#include
#include //need to include in order to use getch
using namespace std;

//function prototypes
float getMiles();
float getNumGallons();
float calcMpg(float distance, float galUsed);

int main()
{

float miles = 0.0;
float gallons = 0.0;
float milesPerGal = 0.0;

//enter input items
miles = getMiles();
gallons = getNumGallons();

//calculate miles per gallon
milesPerGal = calcMpg(miles, gallons);

//display output item
cout << fixed;
cout.precision(1);
cout << "Miles per gallon: " << milesPerGal << endl;

getch (); // makes your prog. window stays still
} //end of main function

//*****program-defined functions*****
float getMiles()
{
float numMiles;
cout << "Enter the number of miles: ";
cin >> numMiles;
return numMiles;
} //end of getMiles function

float getNumGallons()
{
float numGallons = 0.0;
cout << "Enter number of gallons: ";
cin >> numGallons;
return numGallons;
} //end of getNumGallons function

float calcMpg(float distance, float galUsed)
{

cout << "Enter distance / galUsed: ";

return distance / galUsed;
} //end of calcMpg function

//It can compile now
• Member Posts: 0

________ < http://forcoder.org /> free video tutorials and ebooks about { Go Scratch C Java PHP MATLAB Swift Visual Basic C# Delphi JavaScript Perl Ruby C++ R Visual Basic .NET Python PL/SQL Objective-C Assembly Lisp Transact-SQL Alice Bash COBOL D Apex Prolog ABAP Dart Crystal Julia FoxPro Scheme Erlang Lua Ada Awk Logo Fortran Scala Hack LabVIEW Rust VBScript ML Clojure Kotlin SAS F# } _______