B4Coder

🎧 Help Desk · Mission 6 of 6

🧮 Balanced Brackets

Students type formulas into the desk's calculator, and some forget a bracket. Check each formula: does every ( have its )?

Your mission

  1. Ask "Formula?" into text. Make open = [ ] and ok = true.
  2. Go through text letter by letter. At "(", Push it onto open. At ")": if open is empty, ok = false; otherwise Pop open.
  3. At the end, if ok && length(open) == 0, Tell "Balanced"; otherwise Tell "Not balanced".

Getting the mission ready…