I'm trying to solve this problem:
Write a program to produce a number table as described here. This table should be built from a single integer value provided by the user. The program will display a square 5X5 of various numbers. The entered number should show up in the table making a capital L shape. Every other spot inside the box should also be filled with a number. Those excess numbers should start with one bigger than the entered number and increment by one for every additional number used.
For example, the following output should be produced when the user inputs the starting value 15:
Gimme a starting value: 15 15 16 17 18 19 15 20 21 22 23 15 24 25 26 27 15 28 29 30 31 15 15 15 15 15
My code is below and I keep getting an error on line 15 (for (a := 1 to 5): Syntax error, unexpected assignTkn, expecting '(', Near << := >>
I can't figure out how to fix it:
program NumberTable;
#include("stdlib.hhf")
static
StartingVal: int32;
a: int32;
b: int32;
begin NumberTable;
stdout.put("Starting value: ");
stdin.get(StartingVal);
stdout.newln();
for (a := 1 to 5)
for (b := 1 to 5)
if (b = 3 or a = 5)
stdout.put(StartingVal, " ");
else
stdout.put(StartingVal + (a - 1) * 5 + (b - 1), " ");
endIf;
endFor;
stdout.newln();
endFor;
exit();
end NumberTable;`
I tried adding brackets and 'do', still get the same error. I feel like it's obvious, but i'm not sure what i'm missing
To be honest, I don't fully understand the purpose of your program. But I applied all the necessary corrections to make it compile-able.
The syntax of the for-loop is for( initStmt; BoolExpr; incStmt ) do
Logical or is represented by ||
Also the calculation will not work as expected, because HLA is not so high-level. You need to break the calculation steps down and perform it in processor registers.
exit() does not exist this way and needs to be removed.
Output Starting value: 15