Question: I’m trying to write a function that tells the user if they are old enough to drink.

Whenever I run what I wrote it says there is a syntax error in line 3 where it says “If age> 20: ”. What am I doing wrong:

```
age = int(input("how old are you?")

if age > 20:
    print("You're old enough to drink")
else:
    print("Go drink some apple juice")

```

Answer: 
Take a look at the `map()` function for your use case  

<https://www.arduino.cc/reference/en/language/functions/math/map/>

```cpp
int val = 0;  // assign at declaration

void loop()
{
  val = analogRead(POTENTIOMETER_PIN);  // read value
  val = map(val, 0, 1023, 0, 180);      // convert into 180 range
  Serial.println(val);                  // display value
}

```

Internally, this makes use of a larger type than the humble `int`, using a `long`, which is (probably) 32-bits rather than 16

From the documentation above

```
long map(long x, long in_min, long in_max, long out_min, long out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

```

---

The reason this works better for you and can do the math correctly is because a 16-bit number doesn't contain enough precision for the multiplication, while `map()` uses a 32-bit number internally to represent the value while it does the math on it!

Specifically, **if, during your logic you rely on 16-bit math, the value exceeds that ~32768 range, it will *wrap around* and become negative!**

This is known as [Integer Overflow](https://en.wikipedia.org/wiki/Integer_overflow), which the Wikipedia article linked has a great demonstration of using a car odometer  

the 100,000th mile is *overflowing* and wraps around to 1 because the first digit doesn't have room and so is truncted

[![integer_overflow](https://i.stack.imgur.com/Zx1PZ.png)](https://i.stack.imgur.com/Zx1PZ.png)

---

Some more labouring the point from the `int` docs on Arduino, specifically because while there is much debate (including *why* Arduino chooses to supply `int` at all) it's generally good practice to always specify exactly the type you you're after such as `uint32_t`, rather than relying on `int`, which frustratingly can have a different size on different device targets

<https://www.arduino.cc/reference/en/language/variables/data-types/int/>

> 
> On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1).
> 
> 
> 

> 
> On the Arduino Due and SAMD based boards (like MKR1000 and Zero), an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) - 1).
> 
> 
>
It would seem that your compiler defines int as being a 16 bit signed number.

Thus there is a limit of 32767 to -32768.

You are exceeding this and so the values 'wrap around'.

Try changing the code to use 'long' instead of 'int'.