Computer Science Canada IF button problem. |
Author: | NEOS [ Sun Nov 16, 2008 9:10 am ] | ||
Post subject: | IF button problem. | ||
My problem is that I need the buttons to put 1 or 0 in the first area if pressed and if that happens then the next button that is pressed is put in the second area. (It's a calculator) |
Author: | DanielG [ Sun Nov 16, 2008 11:11 am ] |
Post subject: | RE:IF button problem. |
can you show all your code? it's impossible to run and see what you are trying to do |
Author: | NEOS [ Sun Nov 16, 2008 11:46 am ] | ||
Post subject: | Re: IF button problem. | ||
|
Author: | pavol [ Sun Nov 16, 2008 12:50 pm ] |
Post subject: | RE:IF button problem. |
well, your code doesn't even compile because of ANDcalc (val1, val2) that line. You have declared your function as returning an int but in that line you call it as if it did not return anything. Since ANDcalc() returns a value you need to set it to something like intVariable = ANDcalc(val1, val2) |
Author: | NEOS [ Sun Nov 16, 2008 1:14 pm ] |
Post subject: | Re: IF button problem. |
Sorry I didn't understand what you just said! |
Author: | andrew. [ Sun Nov 16, 2008 2:14 pm ] | ||||
Post subject: | RE:IF button problem. | ||||
Your function ANDCalc returns an integer. But you are calling it like a procedure so it can't return anything so it gives you an error. You used:
But that gives an error because there is nowhere to put the value that is returned. You have to do something like this:
Functions always return a value and that value always has to be stored somewhere either in a variable or using it right away (put ANDCalc (val1, val2)). |
Author: | NEOS [ Sun Nov 16, 2008 2:49 pm ] |
Post subject: | Re: IF button problem. |
ok that answers that but my original question wasn't answered. I want it to, when, the user presses a button, 1 or 0, it puts it in a certain area then when they press a second button, 1 or 0, it will put it in the second area. I've tried but the 0 would just disappear.... |
Author: | pavol [ Sun Nov 16, 2008 10:51 pm ] | ||
Post subject: | Re: IF button problem. | ||
I apologize ahead of time for nagging you about this again...but your code doesn't compile! The problem I stated earlier prevents you from running the program, so I have no clue how you even test your program if it doesn't run...? So assuming I remove that one line that is causing the problem and run your program again, there's a couple of things: your program doesn't actually do any logical testing yet, although I'm sure you're already aware of this. Next, for your problem about the 1's and 0's, you have designated the position of (3, 16) to 1 and the position (3, 26) to 0, this means that the only combination of 1 and 0 that I press which will show up on the screen is 1 followed by 0. This is because when you press 1, it will put it in position 16, then you chose your test, which will be displayed in position 20, and finally 0 will be put in position 26. Lets say I try the combination of 0-1 instead. Fist my 0 gets put in position 26, then the logical test gets put into position 20...overwriting what was in position 26, and finally when I put 1, it will be in position 16, overwriting everything else. Therefore, you need to adapt your code for what happens when 1 and 0 is pressed so that they can put 1 or 0 in the position given by both (3, 16) and (3, 20). This can be simply accomplished by the addition of a boolean variable. Ex/
You can then similarly adapt your code for the 0 button, etc. I hope this helps a bit more. |
Author: | NEOS [ Mon Nov 17, 2008 12:41 pm ] |
Post subject: | Re: IF button problem. |
Where do I put it? |
Author: | NEOS [ Wed Nov 19, 2008 1:01 pm ] |
Post subject: | RE:IF button problem. |
Bump |