+ 3
How is my program not outputting the requirements?
I'm suppose to write a program that takes a integer of the number of people and then their names. The program is supposed to print out a space separated list of initial. My output looks the exact same as the test cases but it still fails. Test case 1: Input: 4 Andy Smith Jamie Anderson Walt Peterson Trent Rogers Expected output: AS JA WP TR My output: AS JA WP TR https://code.sololearn.com/cet95xjX22M5/?ref=app
18 Answers
+ 2
Try by adding getchar() after cin
cin >> numPeeps;
getchar(); // consume line feed
Loop till i < numPeeps ; only not <=
+ 2
Malachite Is that getchar() solution not working?
+ 2
Malachite
By cin , the input pointer will not go into next line. So getline() at first reads empty new line character only because next input is in next line.
getchar() comsume line feed. And input pointer goes to next line. So readline() reads first string input line at first time then. i < numPeems is enough then.
Hope it helps...
You're welcome..
+ 1
Task:
Given a list of first and last names, take the first letter from each name to create initials and output them as a space-separated string.
Input Format:
The first input denotes the number of names in the list (N). The next N lines contain the list elements as strings.
Output Format:
A string containing the initials of each name in the original list, separated by spaces.
+ 1
at the print try this
cout << inti << '#';
i tried and the # symbol was a lot far away from the text. it means you print a lot white spaces at the end
+ 1
Thank you anyway
+ 1
Malachite i think i found the issue. you print 1 white space at the beginning not the end, try print a character before print the result and you will see it
+ 1
Jayakrishna the getchar() worked. I'm not exactly sure how or why but I'm happy to have the fix so now i can figure that part out. Sorry I missed that at first. I was a bit distracted. Anyway thank you both for the help. 🙂
+ 1
Oh ok. That's great to know. Thank you
0
what's the issue exactly? It stuck or output wrong results?
try change your stringstream to this, i had many times this problem.
stringstream sso;
sso << names;
0
The sstream is working. It fills in properly. For whatever reason my output isn't matching the required output even though they look identical
0
oh then probably you have a space at the very end or you need to have but you not have?
0
Also if I loop til just i< numpeeps I won't have the last set of initials.
0
no white space. In the code I erased the final spot just to prevent that. I also tried without and still no luck
0
you have <=
0
Yes I do. If it's erased it won't get the last initials. I've also tried different versions of that
0
weird maybe sololearn get my input wrong, so i think I can't help sorry
0
Hmm it just printed out right after my output when I tried