Since your program is a single file, it
must be named "Main.jack" and it must be class "Main".
If I change your first line to read
class Main /*was Guess_Number*/ {
I can compile and run your code with no crash. It immediately exits due to errors in you program's logic.
Make sure that there are no other .jack files and no other .vm files in the directory with your game.
If there are other .jack files, the JackCompiler will compile all of them to .vm files. If there are other .vm files, the VMEmulator will load them all depending on how you use it. This can cause you problems with unexpected code running.
----------
A simple way to debug is to put printString calls in the code to tell you where it gets to.
class Main /*was Guess_Number*/ {
function void main () {
var int n, number, tries;
let number = 64;
let tries = 3;
let n = 0;
do Output.printString("*** before the while"); do Output.println(); /* DEBUG */
while ((tries > 0) & (n > number)) {
do Output.printString("*** top of the while"); do Output.println(); /* DEBUG */
let n = Keyboard.readInt("Guess the number:");
if (n > number) {
do Output.printString("Lower!");
let tries = tries - 1;
}
else {
if (n < number) {
do Output.printString("Higher!");
let tries = tries - 1;
}
else {
do Output.printString("Correct!");
}
}
}
do Output.printString("*** after the while"); do Output.println(); /* DEBUG */
if (tries = 0) {
do Output.printString("Out of tries!");
}
return;
}
}
Running this version prints
*** before the while
*** after the while
and puts up the "Program Halted: Main.main finished execution" message box.
--Mark