Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Why is this working?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TipsyCzar




PostPosted: Thu Dec 01, 2016 2:00 pm   Post subject: Why is this working?

So I made another project for my computer science class. It's a simple cell phone with various applications on it.

However, what confuses me is one part that works perfectly, which I think shouldn't. It's in the procedure "instructions", where the user is given two prompts : one to load another section of the instruction manual and another to load the starting menu. Both if commands for the two prompts were given identical codes to execute, and yet they do different things. The section you should look at is marked in a comment.

I'm happy it works as it does, but the more I look over the code, the more I get confused. Also, I would appreciate a general comment on the code too.

Thanks



Unnamed.t
 Description:

Download
 Filename:  Unnamed.t
 Filesize:  12.46 KB
 Downloaded:  141 Time(s)


Unnamed.t
 Description:

Download
 Filename:  Unnamed.t
 Filesize:  12.46 KB
 Downloaded:  139 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
TipsyCzar




PostPosted: Thu Dec 01, 2016 2:01 pm   Post subject: RE:Why is this working?

I accidentally added the same program twice, you need only download one.
Insectoid




PostPosted: Thu Dec 01, 2016 3:01 pm   Post subject: RE:Why is this working?

What happens if you delete the 2nd if statement in that loop?
TipsyCzar




PostPosted: Thu Dec 01, 2016 8:02 pm   Post subject: Re: RE:Why is this working?

Insectoid @ Thu Dec 01, 2016 3:01 pm wrote:
What happens if you delete the 2nd if statement in that loop?


The 2nd if statement will (should) bring you to the main menu. Deleting it would mean you are unable to go to the menu without doing the 1st if statement (which brings you to part 2 of the instructions).



Although, looking over the program again, I saw why it worked as it did. Technically, it doesn't actually bring you to the menu. It loads the 2nd part of the instructions. However, immediately after that, another prompt appears in the same spot where you clicked without a delay. If the mousewhere coordinates are still the same, it clears the screen and brings you to the menu.

Happy coincidence, I guess.
Insectoid




PostPosted: Thu Dec 01, 2016 9:34 pm   Post subject: RE:Why is this working?

Yup, that's exactly what's going on. I'd almost think it was intentional, if sloppy. It kinda works here, but 99% of the time, this will cause strange behaviour in the program. The fix is to check for mouse button presses/releases, instead of just the button being down.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: