Computer Science Canada Code help |
Author: | KevinW [ Wed Nov 15, 2006 5:52 pm ] | ||||
Post subject: | Code help | ||||
With this program, i'm trying to input a letter and remove the vowels... I got this to work after toying around with the ifs. but i'm wondering why this works opposed to this type of coding...
|
Author: | wtd [ Wed Nov 15, 2006 6:21 pm ] | ||
Post subject: | |||
First thing's first... kill the global variables and use small, tightly focused functions and procedures (but only these if you really have to). For instance:
|
Author: | TokenHerbz [ Wed Nov 15, 2006 10:23 pm ] |
Post subject: | |
Nice wtd ![]() |
Author: | Wolf_Destiny [ Fri Nov 17, 2006 11:11 pm ] | ||||||
Post subject: | |||||||
Also the reason that:
Didn't work is due to the structure of your if statement. If letter not a OR e OR i OR o OR u then display the letter. Well the letter won't be more then one at any given time right? It can't be 'a' and 'u' right? So say it is 'a' lets analyse the IF statement. if word (c) not= "a" %But is is equal to "a" so this is false or word (c) not= "e" %It isn't equal to "e" so this is true or word (c) not= "i" %It isn't equal to "i" so this is true or word (c) not= "u" %It isn't eqaul to "u" so this too is true then So what is our final result from that? false or true or true or true Is either false or true = true? Yeah! So that is true! are any of: true or true or true = true? Yeah! So that's true too! The whole if statement is true, and always will be since only one parameter needs to be true for the whole thing to be true. "So what do I do?" Well since you don't want it to be ANY of the vowels, it can't be "a" AND it can't be "e" AND it can't be "i" ect... So:
And if you want to do as wtd says, then kill the global variables...
Ha! I did it without fancy neat and intelligent programming! Woot for begin and end! ~Wolf_Destiny |