Re: First C program, NIM gane

Posted 12 March 2008 - 05:49 PM

Well, the errors are gone, but important is that you should always code inside a program like notepad or any other simple text editor; do not ever copy your code to and from a word-processor like WORD or Open Office Writer.

The formatting in these programs can create a beginner's nightmare.

And when you want to assign a value to a variable say:

int counter;

counter = pile1; and not pile1 = counter; the latter statement will assign the value of counter to pile1 and not what you actually want to happen.

Re: First C program, NIM gane

Posted 12 March 2008 - 09:17 PM

Here is my most recent code. It seems to make it correctly to the line in made in the code but then exits after that. I have been looking at this for far to long and a fresh set of eyes could do it good.

It asks for a pile (1, 2 or 3) then asks how many sticks (*) to remove from the pile. I have if statement s to subtract from the pile chosen. It seems to skip by these statements which must mean that my variable "pile" is not equal to 1,2, or 3.

Here is my most recent code. It seems to make it correctly to the line in made in the code but then exits after that. I have been looking at this for far to long and a fresh set of eyes could do it good.

It asks for a pile (1, 2 or 3) then asks how many sticks (*) to remove from the pile. I have if statement s to subtract from the pile chosen. It seems to skip by these statements which must mean that my variable "pile" is not equal to 1,2, or 3.

Re: First C program, NIM gane

Posted 12 March 2008 - 09:20 PM

There don't seem to be any loops in here that would make it go back to the beginning. So, it asks for the number of sticks, changes the value of the pile you suggested, and then exits. There are no print statements after your pile math, so it looks like it is skipping the statements.

You'll need to add a loop with an endgame condition to make it go back to the beginning of the program.