{
  "format": "tokbit",
  "version": 1,
  "name": "How old are you and adulthood",
  "main": [
    {
      "id": "u1",
      "kind": "declare",
      "name": "birth_day",
      "type": "int"
    },
    {
      "id": "u2",
      "kind": "declare",
      "name": "birth_month",
      "type": "int"
    },
    {
      "id": "u3",
      "kind": "declare",
      "name": "birth_year",
      "type": "int"
    },
    {
      "id": "u4",
      "kind": "doWhile",
      "body": [
        {
          "id": "u5",
          "kind": "input",
          "target": "birth_day",
          "prompt": "Day of birth (1–31):"
        },
        {
          "id": "u6",
          "kind": "if",
          "condition": "birth_day < 1 or birth_day > 31",
          "then": [
            {
              "id": "u7",
              "kind": "output",
              "values": "\"The day must be from 1 to 31.\""
            }
          ],
          "else": []
        }
      ],
      "condition": "birth_day < 1 or birth_day > 31",
      "comment": "Asks again until the day makes sense."
    },
    {
      "id": "u8",
      "kind": "doWhile",
      "body": [
        {
          "id": "u9",
          "kind": "input",
          "target": "birth_month",
          "prompt": "Month of birth (1–12):"
        },
        {
          "id": "u10",
          "kind": "if",
          "condition": "birth_month < 1 or birth_month > 12",
          "then": [
            {
              "id": "u11",
              "kind": "output",
              "values": "\"The month must be from 1 to 12.\""
            }
          ],
          "else": []
        }
      ],
      "condition": "birth_month < 1 or birth_month > 12"
    },
    {
      "id": "u12",
      "kind": "doWhile",
      "body": [
        {
          "id": "u13",
          "kind": "input",
          "target": "birth_year",
          "prompt": "Year of birth:"
        },
        {
          "id": "u14",
          "kind": "if",
          "condition": "birth_year > year()",
          "then": [
            {
              "id": "u15",
              "kind": "output",
              "values": "\"The year can't be in the future.\""
            }
          ],
          "else": []
        }
      ],
      "condition": "birth_year > year()"
    },
    {
      "id": "u16",
      "kind": "declare",
      "name": "age",
      "type": "int",
      "init": "year() - birth_year",
      "comment": "Age by the calendar year; year() is this year."
    },
    {
      "id": "u17",
      "kind": "if",
      "condition": "month() < birth_month or (month() == birth_month and day() < birth_day)",
      "then": [
        {
          "id": "u18",
          "kind": "assign",
          "target": "age",
          "value": "age - 1"
        }
      ],
      "else": [],
      "comment": "No birthday yet this year: one year less."
    },
    {
      "id": "u19",
      "kind": "if",
      "condition": "age == 1",
      "then": [
        {
          "id": "u20",
          "kind": "output",
          "values": "\"You are\", age, \"year old.\""
        }
      ],
      "else": [
        {
          "id": "u21",
          "kind": "if",
          "condition": "age >= 2 and age <= 4",
          "then": [
            {
              "id": "u22",
              "kind": "output",
              "values": "\"You are\", age, \"years old.\""
            }
          ],
          "else": [
            {
              "id": "u23",
              "kind": "output",
              "values": "\"You are\", age, \"years old.\""
            }
          ]
        }
      ],
      "comment": "In Czech 1 rok, 2–4 roky, otherwise let; in English year for 1, otherwise years."
    },
    {
      "id": "u24",
      "kind": "if",
      "condition": "age >= 18",
      "then": [
        {
          "id": "u25",
          "kind": "output",
          "values": "\"You are an adult.\""
        }
      ],
      "else": [
        {
          "id": "u26",
          "kind": "output",
          "values": "\"You will be an adult in\", birth_year + 18"
        }
      ]
    },
    {
      "id": "u27",
      "kind": "if",
      "condition": "month() == birth_month and day() == birth_day",
      "then": [
        {
          "id": "u28",
          "kind": "output",
          "values": "\"Happy birthday!\""
        },
        {
          "id": "u29",
          "kind": "call",
          "call": "note(\"C5\", 200)"
        },
        {
          "id": "u30",
          "kind": "call",
          "call": "note(\"E5\", 200)"
        },
        {
          "id": "u31",
          "kind": "call",
          "call": "note(\"G5\", 200)"
        },
        {
          "id": "u32",
          "kind": "call",
          "call": "note(\"C6\", 400)"
        }
      ],
      "else": [],
      "comment": "Birthday today: a wish and a tune."
    }
  ],
  "functions": [],
  "comment": "Solution to the task “Coming of age”: The program adds whether the person is an adult and, if not, in which year they turn 18.",
  "screen": "fit"
}
