AboutAlex Barry Expertise I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.
Experience Hobby programming since 2000
I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++
Question hello, I need help with my code, I have asked my teacher but she's not that nice and doesnt really make me understand what i have to do. The question to answer is:
Write a program that asks the user for a sentence and
-Prints it with one letter on each line
-Says how many words it has
I been having problems with this question dor 2 weeks now and still cant figure it out, if you could me understand that would be much appreciated
this is the code i have:
CLS
DIM sentence AS STRING
DIM length AS INTEGER
DIM spaces AS INTEGER
DIM letter AS STRING
COLOR 15
space = 0
PRINT "Enter a sentence"
INPUT sentence
FOR i = 1 TO length
letter = MID$(sentence, i, 1)
IF LEN(letter) = spaces THEN
spaces = spaces + 1
END IF
PRINT "length "; length
NEXT i
PRINT "Your sentence has"; LEN(length); "words"
Answer Hi, Jorge,
I think I can point you in the right direction.
Your code for getting the length (your FOR loop) seems to be a little off, so I'll show you how I'd do it:
DIM words AS INTEGER
words = 0
length = LEN( sentence )
FOR i = 1 TO length
' Get the current letter
letter = MID$( sentence, i, 1 )
' If the letter is a space, add a word ( part 2 of the question )
IF letter = " " THEN
words = words + 1
END IF
' Print the letter on the next line ( part 1 of the question )
PRINT letter
NEXT i
' Because the last word won't have a space after it, we add one more
words = words + 1