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):
INPUT "Enter a word : ",word$
REM *** Set the counters to 0 ***
counter_lowercase = 0
counter_uppercase = 0
REM *** Examine the word and if letter is an e then add 1 to counter***
FOR c = 1 TO LEN(word$)
IF MID$(word$,c) = "e" REM Het MID$ commando heeft de variabele en dan de positie van die variabele als opbouw
counter_lowercase = counter_lowercase + 1 REM Dus elke letter wordt in dit loopje bekeken of het een e is.
ENDIF
IF MID$(word$,c) = "E" REM Er wordt onderscheid gemaakt tussen kleine en grote E's en die worden appart geteld.
counter_uppercase = counter_uppercase + 1
ENDIF
NEXT c
PRINT "There are ",counter_lowercase, " lower case e's in ",word$
PRINT "and there are ",counter_uppercase, " uppercase E's in ",word$
REM ***End program ***
WAIT KEY
END
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:
REM ***Get a string***
INPUT "Enter a word : ", word$
REM *** Set count to zero ***
count = 0
REM *** FOR each character in word ***
FOR c = 1 TO LEN(word$)
REM *** IF it's E, add 1 to count ***
IF UPPER$(MID$(word$,c)) = "E"
count = count + 1
ENDIF
NEXT c
REM *** Display count ***
PRINT "There are ",count," e's in ",word$
REM *** End program ***
WAIT KEY
END
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."