Howdy, Stranger!

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

Categories

trying to debug a second program and having trouble

posthimposthim 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

Comments

  • Geeth AsokanGeeth Asokan Member Posts: 127
    : 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
    :
    :

    I replied to this message on another message board!

  • Justin BibJustin Bib USAMember Posts: 0

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

Sign In or Register to comment.