943,694 Members | Top Members by Rank

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

Re: Returning

#include <iostream>
#include <cstdlib>
using namespace std;

// Put you function prototype (declarations) here.



double MPG ( double sizeoftank, double numberofmilest, double gasleftintank)
{


MPG=numberofmilest/(sizeoftank-gasleftintank);
return MPG;
}

system("PAUSE");

}
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 29th, 2008
0

Re: Returning

You need to at least write a main() program, that is the only way you will be able to test your mpg function.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Feb 29th, 2008
0

Re: Returning

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. // Put you function prototype (declarations) here.
  6.  
  7.  
  8. int main ()
  9. {
  10.  
  11.  
  12. }
  13. double MPG ( double sizeoftank, double numberofmilest, double gasleftintank)
  14. {
  15.  
  16.  
  17. double MPG=numberofmilest/(sizeoftank-gasleftintank);
  18. return MPG;
  19. }
  20.  
  21. system("PAUSE");
Reputation Points: 10
Solved Threads: 1
Junior Poster
Jboy05 is offline Offline
124 posts
since Jan 2008
Feb 29th, 2008
0

Re: Returning

You still need to call your function from main(). In main, simply initialise and assign three double variables and pass them into your function.

In main() something like this cout << mpg(d1, d2, d3) << " mpg.\n"; Note, d1, d2 & d3 are the three variables previously initialised and assigned.

We're not bothered about user input at this stage, the whole point is merely to test that your functions works. I can tell you that your function is correct but you need to test it for yourself.
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