I solved a kata that required me to construct a method that would tell you the amount of cards needed to build a house of cards with a specified floor. Below is a description of that kata:

> 
> You want to build a standard house of cards, but you don't know how many cards you will  
> 
>  need. Write a program which will count the minimal number of cards according to the number  
> 
>  of floors you want to have. For example, if you want a one floor house, you will need 7 of 
>  them (two pairs of two cards on the base floor, one horizontal card and one pair to get the 
>  first floor). Here you can see which kind of house of cards I mean: 
>  <http://www.wikihow.com/Build-a-Tower-of-Cards>\*
> 
> 
> Details: the input must be an integer greater than 0, for other input raise an error.\*
> 
> 
> 

Below is my code which solves this kata:

```
def house_of_cards(floors)
  raise StandardError if floors.class != Numeric && floors < 0
  cards_to_add_to_foundation = 0
  floors = floors
  until floors.zero? 
    cards_to_add_to_foundation += ((2 * (floors + 1)) + floors)
    floors -= 1
  end
 cards_to_add_to_foundation + 2
end

```

This was not how I initially wanted to solve the kata. I tried to make this a recursive method as shown below.

```
def house_of_cards(floors)
 return cards_to_add_to_foundation + 2 if floors.zero? 
 cards_to_add_to_foundation = 0
 cards_to_add_to_foundation += ((2 * (floors + 1)) + floors)
 house_of_cards(floors - 1)
end

```

However, this code gives me this error:
 `NameError: undefined local variable or method cards_to_add_to_foundation for main:Object`

Why do I get this error. I have it defined below the second line. If I move the cards\_to\_add\_to\_foundation before the return statement, the function will keep setting the variable to zero which is not what I want. Does anyone have any suggestions to finalize this recursive method. I've been struggling with this for awhile racking my brain on how to do this.

Lastly, while my initial code solves the kata, in this particular solution the `StandardError` portion breaks the kata and will not pass for submission. Is this the normal way how an error i s raised. If you look in the description, the task says to raise an error if the input is less than zero os is not an integer. What other ways are there to raise a general error?

Thanks for the help in advance.