record Question { prompt: string, answer: i64 } fn is_correct(question: Question, answer: i64) -> bool { return answer matches question::answer; } fn summary(label: string, correct: i64, answered: i64, total: i64) -> unit { print(label + ". Correct: " + format_i64(correct) + "; answered: " + format_i64(answered) + "; total: " + format_i64(total) + ".\n"); } fn start_main() -> i64 { let questions: list = [ Question { prompt: "2 + 3?", answer: 5 }, Question { prompt: "9 - 4?", answer: 5 }, Question { prompt: "3 * 4?", answer: 12 }, Question { prompt: "12 / 3?", answer: 4 }, Question { prompt: "7 + 8?", answer: 15 } ]; let total: i64 = length(questions); var index: i64 = 0; var answered: i64 = 0; var correct: i64 = 0; print("Local quiz: " + format_i64(total) + " questions. Type q to stop.\n"); while (index < total) { let question: Question = questions[index]; print("Question " + format_i64(index + 1) + "/" + format_i64(total) + ": " + question::prompt + " "); let line: string = read_line(); if (line matches "q") { summary("Stopped early", correct, answered, total); return 0; } let parsed: result = parse_i64(line); if (parsed::ok) { if (is_correct(question, parsed::value)) { print("Correct.\n"); correct = correct + 1; } else { print("Wrong. Expected " + format_i64(question::answer) + ".\n"); } answered = answered + 1; index = index + 1; } else { print("Retry: " + parsed::error::code + ". Use ASCII digits, for example 5, or q.\n"); } } summary("Completed", correct, answered, total); return 0; }