Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Question regarding a bit of code (its about counting letters):

Author
Message
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 28th Dec 2007 22:38
Like my sig says: I am ploughing through the Vol 1 of the magnificent books that are available for learning DBP and I have come to an exercise which I do not understand. . .

The point is to make a little program that lets you enter a word and then the program will count the lowercase e's and the uppercase E's and show that on-screen.
(see page 214, activity 8.4)

Here's my code (nevermind the dutch remarks, its just for myself):


It does exactly what the activity wants me to do, but yet, if I look into the solutions of the book, this code is printed:



I really don't see how this code counts both lowercase and uppercase E's. I fail to see why my code isn't more effective.
Could anyone elaborate on this, please?


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
DB PROgrammer
17
Years of Service
User Offline
Joined: 9th Feb 2007
Location: Nowhere But Everywhere
Posted: 28th Dec 2007 23:09
It looks like there code counts any type of e upper or lower as in the code "UPPER$" changes the letter to a capital, so even if it was a lower case e it would make it a capital one and then count it. There code does not separate the different case e's when it counts them so you might have misunderstood the book when it said to count the upper and lower case e's.

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 28th Dec 2007 23:43
Well you could expand on your own code and do one better than the example in the code by subtracting the numbers of lowercase "e"'s from all the "e"'s like so:


Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 28th Dec 2007 23:52
Well the exercise says (and I quote):

Change the program again so that both upper and lower case E's are counted. (HINT: Use UPPER$)

I still think my code is better. It at least reflects the outcome of the exercise better?


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 29th Dec 2007 02:38
well thats what i meant by the code i showed
it first counts the lower case "e"s then it changes all the "e"s regardless if its upper or lowercase to uppercase and counts them
then if u subtract the number of lower case form uppercase you get the true uppercase value which u can display

but i guess you code does exactly that it just doesn't use UPPER$ which i guess you don't have to use since its just a hint
so i guess in away your code is better

Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 29th Dec 2007 14:50
Thanks for the replies guys!
Phantom: I don't see how your hint will add to my code...
I don't want to be a cheeky bastard, because I really do appreciate the help!
But here's the thing: You keep both my counters intact, so the program already counts both lowercase e's, then you let it change the given word to uppercase letters and recount the uppercase E's?
Why would this be better than my initial code? The way I see it I have already established two counters for the task at hand, one uppercase, one lowercase. My code even has one line of code less!
A dull subject anyway, I know, but it's more about the logic behind it than the actual code.

Windowskiller: The exercise told me to count both, re-read the thread.


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 29th Dec 2007 17:21
Ah now I see what you mean. its a matter of how you read it then. 'Count both' suggests to me that I should make a program which counts both amounts of E's. . .
Only if I look at the solution, in hindsight, one might discover that it would have been sufficient to do one or the other.


Anyway, I am not after a word game (pun intended!), I was merely wondering if I had done something wrong and quite frankly, I still think my code is the better!


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 1st Jan 2008 01:12
haha well you severly misunderstood me
i was referring to the hint that the book oferred. the book gave a hint to use UPPER$ so i was saying my code uses that
i was saying you code was better not mine because it did the excat same thing in less code the only thing is it didn't use UPPER$ which really didnt matter
thats wat i had initially said
understand?

Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 2nd Jan 2008 00:24
Clear as glass.


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 2nd Jan 2008 02:46 Edited at: 2nd Jan 2008 02:48
haha yay!
ive started readin that book too, to familiarize myself with everyithin again except im only on like chapter 3 after 1 week
advanced procrastination is an art

Login to post a reply

Server time is: 2024-09-27 08:25:03
Your offset time is: 2024-09-27 08:25:03