# Bouncing Balls

## [Bouncing Balls](https://www.codewars.com/kata/5544c7a5cb454edb3c000047)

A child is playing with a ball on the nth floor of a tall building. The height of this floor, *h*, is known.

He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).

His mother looks out of a window 1.5 meters from the ground.

How many times will the mother see the ball pass in front of her window (including when it's falling *and* bouncing?

## Three conditions must be met for a valid experiment:

* Float parameter "h" in meters must be greater than 0
* Float parameter "bounce" must be greater than 0 and less than 1
* Float parameter "window" must be less than h.

**If all three conditions above are fulfilled, return a positive integer, otherwise return -1.**

### Note:

The ball can only be seen if the height of the rebounding ball is strictly greater than the window parameter.

### Example:

```
- h = 3, bounce = 0.66, window = 1.5, result is 3

- h = 3, bounce = 1, window = 1.5, result is -1 

(Condition 2) not fulfilled).
```

## Solutions

#### 👴 C

```c
int bouncingBall(double h, double bounce, double window)
{
    if(!(h > 0 && bounce > 0 && bounce < 1 && window < h))
      return -1;

    char counter = 1;
    double bounce_h = h;

    while(1)
    {
      bounce_h = bounce_h*bounce;
      if(bounce_h >= window)
        counter+=2;
      else
        break;
    }

    return counter;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anton-veselskyi.gitbook.io/codding-problems-solutions/codewars/6-kyu/bouncing-balls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
