Computer Science Canada Program is stuck at "Executing." |
Author: | gayden [ Mon Mar 02, 2015 10:36 am ] | ||
Post subject: | Program is stuck at "Executing." | ||
Not sure if the purpose of the program is really relevant or not, but basically it's meant to complete Shawnar's Process, which dictates: "Given any positive number, you can perform the following operations on it: -If even, divide by two -If odd, multiply by three and then add one and eventually you will reach the number one. Example: 13 13 * 3 + 1 = 40 40 / 2 = 20 20 / 2 = 10 10 / 2 = 5 5 * 3 + 1 = 16 16 / 2 = 8 8 / 2 = 4 4 / 2 = 2 2 / 2 = 1 Anyway, when I run the program it sort of pauses at line 13. The Turing window says "Executing." I am given no error.
|
Author: | Insectoid [ Mon Mar 02, 2015 11:23 am ] | ||
Post subject: | RE:Program is stuck at "Executing." | ||
This loop never exits under some condition. This is because posnum never changes, so unless xnum = 1 is satisfied after the first iteration of the loop, it will never exit. |
Author: | gayden [ Wed Mar 04, 2015 10:34 am ] | ||
Post subject: | Re: RE:Program is stuck at "Executing." | ||
Insectoid @ Mon Mar 02, 2015 11:23 am wrote: This loop never exits under some condition. This is because posnum never changes, so unless xnum = 1 is satisfied after the first iteration of the loop, it will never exit.
So if I change every isntance of 'xnum' in the program to 'posnum,' so that posnum does now change, it should work right? edit: Now I run into more problems. I shall update when I figure it out. edit2: Program now looks like:
|
Author: | Clayton [ Thu Mar 05, 2015 3:43 pm ] |
Post subject: | RE:Program is stuck at "Executing." |
What problems are you running into exactly? Not being able to test your code at the moment, so I might be missing something small, but at a glance, this appears like it should do what you're looking to do. |
Author: | Tony [ Thu Mar 05, 2015 4:07 pm ] |
Post subject: | RE:Program is stuck at "Executing." |
Quote: exit when posnum = 1 Does 1.0 equal to 1? Sometimes, but not always. real (known as float in other languages) are designed to for less-than and greater-than comparisons, not for equalness. |
Author: | gayden [ Fri Mar 06, 2015 10:07 am ] |
Post subject: | Re: RE:Program is stuck at "Executing." |
Tony @ Thu Mar 05, 2015 4:07 pm wrote: Quote: exit when posnum = 1 Does 1.0 equal to 1? Sometimes, but not always. real (known as float in other languages) are designed to for less-than and greater-than comparisons, not for equalness. I'm not even sure why posnum and originalnumber were declared as real numbers as opposed to integers. My mistake ![]() Clayton @ Thu Mar 05, 2015 3:43 pm wrote: What problems are you running into exactly? Not being able to test your code at the moment, so I might be missing something small, but at a glance, this appears like it should do what you're looking to do.
I fixed it now. Although now I have a question with the same program. "For every one hundred iterations the program should ask the user if they want to continue." Is there a way I can automate this, or do I have to do a separate if statement for multiple multiples (heh) of 100 |
Author: | Dreadnought [ Fri Mar 06, 2015 10:47 am ] |
Post subject: | Re: Program is stuck at "Executing." |
There is a way you can automate this. rem and mod may be helpful, but are not necessary to accomplish what you are trying to do. |