# Review problems 2

<!--
Determine precedence of operators
-->
::::{activity} Operator precedence
:label: operator-precedence-mc

You want to calculate the following formula in C#.

$$ y = ax^{3}+ (b-1) x+c $$

Which of the following expressions calculate the formula?

1. `y = a * x * x * x + b - 1 * x + c`{l=cs}
1. `y = a * (x * x * x) + (b - 1) * (x + c)`{l=cs}
1. `y = a * (x * x * x) + b - 1 * x + c`{l=cs}
1. `y = a * x * x * x + (b - 1) * x + c`{l=cs}
1. `y = (a * x) * x * x + b - 1 * (x + c)`{l=cs}
1. `y = (a * x * x * x) + (b - 1) * x + c`{l=cs}
1. `y = a * Math.Pow(x, 3) + b - 1 * x + c`{l=cs}

You don't have to write any code to answer this question

:::{dropdown} Hint
- section {ref}`operator-precedence`
- section {ref}`math-expressions`
:::
::::

<!--
- Find input and output of a program in an implementation of a mathematical formula
-->
:::{activity} Coding a mathematical formula
:label: coding-a-mathematical-formula
Write a program that receives the required input from the user and calculates `y` from {ref}`operator-precedence`. Your program should be able to accept decimal numbers like 1.2, -0.9.

For example, for a=1, b=1, c=1, and x=0.1, you should get 1.001.

Assume that the user will always provide numbers and no letters.

```{warning}
Dependent on the country you have selected on your operating system, you have to use `,` or `.` as the decimal separator. Otherwise `0.1` will be interpreted as `1`.
```

```{dropdown} Hint
- section {ref}`operator-precedence`
- section {ref}`conversion-between-datatypes`
  - `Convert.*` or `TryParse`
```
:::

<!--
- use control loop for invalid input
- design control loop using flowchart
- differentiate between TryParse and Convert functions
-->
:::{activity} Processing invalid user input
:label: processing-invalid-user-input
Upgrade your solution from {ref}`coding-a-mathematical-formula` so that your program does not choke 🤮 if the user provides wrong input like this:

```text
Let me calculate y = ax^3 + (b-1)x + c for you 🙂
a? 😛
Unhandled exception. System.FormatException: The input string '😛' was not in a correct format.
```

Your program should react recover like a boss as follows:
```text
Let me calculate y = ax^3 + (b-1)x + c for you 🙂
a? 😛
Your input is not a decimal number, please try again. ↺
a?
```

Steps:
1. Design a control flow using a flowchart
1. Implement your flowchart using C#.

If you copy paste blocks, this is fine for this problem. You don't have to implement any functions. We will implement functions in another problem.

```{dropdown} Hint
- section {ref}`flowchart`
- section {ref}`conversion-between-datatypes`
  - `Convert.*` vs `TryParse`
- section {ref}`boolean-logic`
  - negation
```
:::

<!--
TODO scope?
modularizing asking for input
-->

<!--
- implement randomness
- use arrays
- use modulo
- (using classes)
-->
:::{activity} Drawing balls
We will use [raylib](https://www.raylib.com/) in this activity. Raylib is a simple library to develop games.

Install it by searching for `Raylib-cs` in the package manager (`NuGet` {{nuget}}).

Then use the following template to test your installation:

```cs
using Raylib_cs;

Raylib.InitWindow(800, 480, "Hello World");

while (!Raylib.WindowShouldClose())
{
    Raylib.BeginDrawing();
    Raylib.ClearBackground(Color.White);

    Raylib.DrawText("Hello, world!", 12, 12, 20, Color.Black);

    Raylib.EndDrawing();
}
```

If the template above does not work, then try the template [here](https://github.com/raylib-cs/raylib-cs/?tab=readme-ov-file#hello-world)

Milestones:
1. Draw a single ball
1. Draw 10 balls in a row
1. Draw three rows of balls with 10 balls in each row
1. Draw the ball on another location. In other words, make it move.
1. Create 10 balls with random colors at random places.
1. Add velocities to each ball, so that their position changes at each frame, i.e., `pos = pos + vel` for x and y coordinates.
1. If a ball goes outside the view, it should pop up again at the other side of the screen.
:::


::