0

I'm really struggling with this - I seem to be going in circles and going nowhere!

This is what i understand to complete this assignment: First, Ask user for name, Use GetString to capture and call it name Then create a for loop, then have it print the 1st element in name. Here's my first problem: this prints a the first char in name many times (as many chars there are in name) I realize that this is because the loop is running for the number of chars in name and that's why I get multiple chars, but I'm not sure how to only get the first char to print? enter image description here Secondly, I understand that to get the next initials, I will have to run another loop that looks for the char after a space. But I'm not sure how to do this?

Thanks

1

You understand what is needed, but it seems like you're overthinking everything. There's an old saying in programming: "KISS - Keep It Simple, Stupid!" This is something I remind myself of with just about every project I work on.

If you want to print out only the first character, why do you feel that it is necessary to do so inside of a loop? Why not simply just print out the first character? All the loop does is repeat it over and over, which you don't want.

Next, you do want to execute a loop over the remainder of the string. You've already written the pseudocode for the contents of the loop: run a loop that looks for the char after a space Step 1 - test for a space. Step 2 - if space is found, print the next character. It's that simple. Just remember not to go past the end of the string when you try to print.

If this answers your question, please click the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • So to test for a space, I run a while loop? and ask if within the string there exists a space? Dec 2 '15 at 0:06
  • So to test for a space, I have run a for loop and asked if a new variable i has a ' ' (space). I tried this and then had it print out YES if it was working and it worked... So, last part which I'm struggling with is how to ask for the char after the space. Thank YOU! Dec 2 '15 at 0:21
0

I figured out how to find the next character after space. I just +1 to the variable! Looks like I'm done. Thanks for the help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .