943,650 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2391
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 28th, 2008
0

Re: Returning

double MPG ( double sizeoftank, double number of milest, double gasleftintank)
{
double numberofmilest;

numberofmilest=sizeoftank/gasleftintank;
return numberofmilest;
}

Done
I have not run the function in a program, its the freaking math of this thats pissing me off, this shit is frustrating
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 28th, 2008
0

Re: Returning

Click to Expand / Collapse  Quote originally posted by Jboy05 ...
double MPG ( double sizeoftank, double number of milest, double gasleftintank)
{
double numberofmilest;

numberofmilest=sizeoftank/gasleftintank;
return numberofmilest;
}

Done
I have not run the function in a program, its the freaking math of this thats pissing me off, this shit is frustrating
miles / gallons = mpg
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Feb 28th, 2008
0

Re: Returning

double MPG ( double sizeoftank, double number of milest, double gasleftintank)
{
double numberofmilest;

sizeoftank=numberofmilest/gasleftintank;
return sizeoftank;

}

i switched the bolded statement around if miles/gallon will yeild mpg then I guess this is right...let me rephrase that I hope this is right....
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 28th, 2008
0

Re: Returning

Ok, I can see where you are confused and I apologise accordingly. I re-read your initial first post and I skipped the bits about the information to be input being 1. size of tank, 2. gallons left and 3. miles travelled. I assumed (lesson never assume) that gallons used was inputted directly. In that regard, yes, there are three (not two as I previously mentioned) arguments to be passed into the function. In the function simply deduct gallons left from size of tank and that equals gallons used. From there it's a straight out mpg calculation.
Last edited by superjacent; Feb 28th, 2008 at 9:56 pm. Reason: spelling.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Feb 28th, 2008
0

Re: Returning

how would I go about using three agruments to yield the number of miles a car can travel with one gallon of gasoline
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 28th, 2008
0

Re: Returning

Click to Expand / Collapse  Quote originally posted by Jboy05 ...
how would I go about using three agruments to yield the number of miles a car can travel with one gallon of gasoline
Ok, here's the formula:

miles travelled / (size of tank - gallons left) = mpg.

mpg is miles per gallon.

miles : 1000
size (gallons) : 60
left (gallons) : 10
1000 / (60-10) = 20 mpg.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Feb 28th, 2008
0

Re: Returning

C++ Syntax (Toggle Plain Text)
  1. double MPG ( double sizeoftank, double numberofmilest, double gasleftintank)
  2. {
  3.  
  4.  
  5. mpg=numberofmilest/(sizeoftank-gasleftintank);
  6. return mpg;
  7. }
Last edited by Jboy05; Feb 28th, 2008 at 10:22 pm.
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 28th, 2008
0

Re: Returning

Click to Expand / Collapse  Quote originally posted by Jboy05 ...
C++ Syntax (Toggle Plain Text)
  1. double MPG ( double sizeoftank, double numberofmilest, double gasleftintank)
  2. {
  3.  
  4.  
  5. mpg=numberofmilest/(sizeoftank-gasleftintank);
  6. return mpg;
  7. }
Try it in a program........see what happens....
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Feb 28th, 2008
0

Re: Returning

i got errors
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 28th, 2008
0

Re: Returning

Click to Expand / Collapse  Quote originally posted by Jboy05 ...
i got errors
What were the errors.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Why wouldn't this work?
Next Thread in C++ Forum Timeline: Combinations of Inheritance and Composition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC