RSS Forums RSS
Please support our C++ advertiser: Programming Forums

User-Defined Function - part 2

Join Date: Mar 2007
Location: Aptos, CA
Posts: 118
Reputation: ft3ssgeek is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 7
ft3ssgeek's Avatar
ft3ssgeek ft3ssgeek is offline Offline
Junior Poster

Re: User-Defined Function - part 2

  #3  
Apr 4th, 2007
Originally Posted by Duki View Post
2. Write the definition of the function funcOne that prompts the user to input a number. The function then changes the value of x to 2 times the old value of x plus the value of y minus the value entered by the user.

Now, with #2 I'm pretty sure I have the function defined right, though I don't know how to test it.

code:

  1. void funcOne ( double in, int x, int y ) //number 2 in my post
  2. {
  3. cout << "Input a value: " << endl ;
  4. cin >> in ;
  5.  
  6. x = x * x + ( y - in ) ; // <----Wrong
  7. }

With this function you are squaring x instead of doubling it (ie use 2*x instead of x*x). To test it, simply do some simple math in your head, using different values of x and y....then implement that in your code...if your code gives you different answers, then, unless you did the math wrong yourself, you know there is a problem with your code...
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:41 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC