Declarations, control structures and statements that may be used in WLPP are restricted to:
Expressions may contain only variable names, integers (written in decimal without a sign), unary & and *, and the binary (two operand) versions of the following operators:
+ - * / % == != <= >= < >
Arrays of consecutive integers may be dynamically allocated using
new and delete [], but their elements can be accessed only
using pointer dereferences, because
WLPP does not include the C++ operator [].
The // notation (and only the // notation) may
be used for comments.
//
// WLPP Program to compute:
// a^b if 0 <= a,b < 10
// -1 otherwise
//
int wain(int a, int b) {
int counter = 0;
int product = 0;
product = 0-1; // only binary minus
if (a >= 0) {
if (b >= 0) {
if (a < 10) {
if (b < 10) {
product = 1;
counter = 0;
while (counter < b) {
product = product * a;
counter = counter + 1;
}
} else {} // must have else
} else {}
} else {}
} else {}
return product;
}