Jul-03-2020, 01:24 AM
(Jul-01-2020, 01:14 PM)deanhystad Wrote: What do you want to do? I don't mean "How are you going to program", but "What do you want to do?" Can you write a concise description of what you want your program to do? That is the first step in writing a program, and that description should be the first thing you mention when asking questions about your program.
I am writing a program that prints every other letter in a string starting with the first letter (index 0). If the string is "Hello World" the output should be:
index = 0 letter = H
index = 2 letter = l
index = 4 letter = o
index = 6 letter = W
index = 8 letter = r
index = 10 letter = d
From the description you would see the solution involves calculating even numbers in the range 0 to the length of the string and using the index to get the letter. You could write this in pseudo code:
for index in range 0 to length(string) print index and string[index]Then convert to code.
If you start with code you risk doing weird things like counting by 1 and using the modulo operator to find even numbers.
Thank you ! got it. i was not thinking correctly. i used what you proposed and used the Range with a step of 2 starting at 0. this solved the exercise.