---
# System prepended metadata

title: Lab7-1

---

1. Create a program that inputs weight (in $kg$) and height (in $meter$), and calculates **bmi** ($bmi = \frac{weight}{height * height}$). 

The example should use **exception handling** to process the **FormatException** that occurs when converting the input string to double.

**If invalid data is entered, display a message informing the user.**

> Hint:
> 1. You can use **double.Parse** method to convert the input string to double.
> 2. You can use exception property **Message** to inform the user.
    > Example: ```Console.WriteLine(formatException.Message);```
> 3. The **finally** block is optional(可寫可不寫)

Input Example: 
```csharp
// valid input (正常輸入)
string input = "123"
double d_input = double.Parse(input);
- - - - -
// invalid input (錯誤輸入)
string input = "123abc12"
double d_input = double.Parse(input); 
// will throw FormatException (we need this)

```
## DEMO

Example code:
```csharp
try
{
  // Input weight: ...Console.ReadLine();
  // Input height: the same
  
  // Calculate BMI
}
catch (FormatException e)
{
	Console.WriteLine(e.Message);
}
finally // optional. You can practice with it.
{
	Console.WriteLine("done");
}
      
```