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

Pass by reference in Function call results not correct

Join Date: Aug 2007
Location: South Dakota
Posts: 1,124
Reputation: vmanes is just really nice vmanes is just really nice vmanes is just really nice vmanes is just really nice 
Rep Power: 7
Solved Threads: 115
vmanes's Avatar
vmanes vmanes is online now Online
Veteran Poster

Re: Pass by reference in Function call results not correct

  #3  
Oct 19th, 2007
Nichito is right about lines 57 & 58 - they have no place in this program, they do nothing useful other than cause it to end before displaying your results. His revision to the calc function body does not change anything, just compresses three lines into one. Saves a couple assignment operations, that's all.

As to the erroneous area calculations, step through the function using the problem values (9,7,3). You should always solve by hand using the algorithm you implement to verify it. In this case, you'll find that your 's' value is 9. What's the value, then, of s-a? What happens when you use that result in the multiplications?

Your code is not giving the correct perimeter. It's giving 1/2 of the perimeter. You need to store the perimeter separately from the 's' value you use in calculations.

And lastly, the value you calculate for 's' is not correct, in most cases. Remember that dividing integers gives only an integer result, so 9/2 is the same as 8/2. You're storing to a double, so do the arithmetic as a double, divide by 2.0.
I am in mourning for my country.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:39 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC