I want to add "ay" after every word in a given line in c++.I have only started learning string. Iam confused. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

I want to add "ay" after every word in a given line in c++.I have only started learning string. Iam confused.

I have tried to solve the problem . But my code doesnot even run.Can anyone please explain the problems in my code. I have also posted the code.Thank you . https://code.sololearn.com/ckZ9udhnrRZv/?ref=app

8th Jan 2020, 1:34 PM
Sidratul Muntaha
2 Answers
+ 3
1. You should remove that space in the first line. It's a stray character not recognized by the compiler. 2. Inside the if-statement, you did not provide any character to compare "str[ i ]" to (the character is empty, which is not allowed). Make sure you put a space in there. 3. What you are doing right now is printing the entire string and an additional "ay" every time you encounter a space. Instead, you might want to check if the current character is a space like you already do, and if it is, print "ay", then print the character regardless of what it is, but not the whole string.
8th Jan 2020, 2:05 PM
Shadow
Shadow - avatar
0
Please remove your code link from question tags, you have it available in the Description 👍
8th Jan 2020, 3:38 PM
Ipang