24 game: Difference between revisions

Correction: the input is not an equation, but an arithmetic expression. An equation requires two sides joined by the = operator, which is explicitly disallowed.
(→‎{{header|C}}: Remove ucontext.h abuse (and use setjmp.h instead).)
(Correction: the input is not an equation, but an arithmetic expression. An equation requires two sides joined by the = operator, which is explicitly disallowed.)
Line 2:
The [[wp:24 Game|24 Game]] tests one's mental arithmetic.
 
Write a program that [[task feature::Rosetta Code:randomness|randomly]] chooses and [[task feature::Rosetta Code:user output|displays]] four digits, each from one to nine, with repetitions allowed. The program should prompt for the player to enter an equationarithmetic expression using ''just'' those, and ''all'' of those four digits. The program should ''check'' then [[task feature::Rosetta Code:parsing|evaluate the expression]]. The goal is for the player to [[task feature::Rosetta Code:user input|enter]] an expression that evaluates to '''24'''.
* Only multiplication, division, addition, and subtraction operators/functions are allowed.
* Division should use floating point or rational arithmetic, etc, to preserve remainders.
543

edits