# What is wrong with this program?

**URL:** <https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343>\
**Category:** Ruby\
**Created:** [August 7, 2009, 5:51am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343 "2009-08-07T05:51:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 5:51am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/1 "2009-08-07T05:51:40Z")

</div>

I don’t understand what is wrong with this program. It gives an error:  
‘findarea’ undefined local variable or method ‘area\_of\_triangle’  
Both ‘findarea’ and ‘area\_of\_triangle’ are clearly defined.

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 6:10am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/2 "2009-08-07T06:10:48Z")

</div>

On Aug 6, 11:51 pm, Prateek A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t understand what is wrong with this program. It gives an error:  
> ‘findarea’ undefined local variable or method ‘area\_of\_triangle’  
> Both ‘findarea’ and ‘area\_of\_triangle’ are clearly defined.
> 
> Attachments:[http://www.ruby-forum.com/attachment/3933/Q3a1.rb](http://www.ruby-forum.com/attachment/3933/Q3a1.rb)
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

Prateek,

You post alot of basic troubleshooting questions on the list. This  
really is something you need to learn to do on your own when  
programming, as no one gets their code right the first time through  
the keyboard.

But for this, a simple Ctrl+F through your own code will give you the  
answer.

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 7:33am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/3 "2009-08-07T07:33:35Z")

</div>

Hi  
two errors there

1 area\_of\_triange=Math.sqrt(s\*(s-side\_a)_(s-side\_b)_(s-side\_c))  
spelling mistake in area\_of\_triange  
2 return area  
area is not defined

Sijo

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 9:23am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/4 "2009-08-07T09:23:54Z")

</div>

On Aug 7, 1:33 am, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Posted viahttp://www.ruby-forum.com/.  
> One of my friends during conversation:

what i have learned from my time at hms both as a tech and as a mentor  
that getting answers is a drug. you get addicted to it. if you find  
some venue through which you happen to get a bunch of answers, be it a  
forum or list or nate coffield, you will abuse it until it turns on you

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 7:30am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/5 "2009-08-07T07:30:21Z")

</div>

On Aug 6, 2009, at 21:10, pharrington wrote:

> Prateek,
> 
> You post alot of basic troubleshooting questions on the list. This  
> really is something you need to learn to do on your own when  
> programming, as no one gets their code right the first time through  
> the keyboard.
> 
> But for this, a simple Ctrl+F through your own code will give you the  
> answer.

Also, seems to be homework based on the filename.

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/6 "2009-08-07T21:03:20Z")

</div>

pharrington wrote:

> what i have learned from my time at hms both as a tech and as a mentor  
> that getting answers is a drug. you get addicted to it. if you find  
> some venue through which you happen to get a bunch of answers, be it a  
> forum or list or nate coffield, you will abuse it until it turns on you

Ya ya… I can quit any time … just give me some more answers please…

ilan

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [August 7, 2009, 9:42am UTC](https://www.ruby-forum.com/t/what-is-wrong-with-this-program/173343/7 "2009-08-07T09:42:04Z")

</div>

Hey,

There are couple of things to be mended in the function “findarea”.

They are

(i) “area\_of\_segment=(4.0/3)\*area\_of\_triangle” But in the prev line,  
you have declared the variable as “area\_of\_triange”. “L(l) is  
missing.”

(ii) You’re returning the variable “area” from the function to the  
main block. But there is no such variable in the function. Guess it  
has to be “area\_of\_segment”.

This should work now.

- Balbao.
