+ 2

name in standard telephone directory format using c++ string

https://code.sololearn.com/c51A1A22A1A2 the question is: 9.5 Write a program that reads full names, one per line, and then prints them in the standard telephone directory format. For example, the input Johann Sebastian Bach George Frederic Handel Carl Phillipp Emanuel Bach Joseph Haydn Johann Christian Bach Wolfgang Amadeus Mozart would be printed as: Bach, Johann S. Handel, George F. Bach, Carl P. E. Haydn, Joseph Bach, Johann C. Mozart, Wolfgang A. did the code according to the solution of the book but it is only taking input continuously, even pressing enter doesn't work.

1st May 2021, 9:24 AM
Ramisa Fariha
Ramisa Fariha - avatar
11 ответов
+ 2
Can you show the code how it is now? I may find the bug.
2nd May 2021, 3:14 PM
bernborgess
bernborgess - avatar
+ 2
I was having a feeling that --n is of no use here and also I have never seen using a decrement or an increment condition outside the while loop...I'll do it again by removing line 31...Thanks a lot @Martin
2nd May 2021, 5:30 PM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
You wanna read a whole line instead of just a word. Use getline (cin,name); instead of cin>>name;
1st May 2021, 3:41 PM
bernborgess
bernborgess - avatar
+ 1
ok thanks @bernborgess
1st May 2021, 4:10 PM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
@bernborgess I have tried your way..still doesn't fix the problem
1st May 2021, 8:33 PM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
Also if you use while to get an unlimited amount of input your last line should be just a ctrl Z key
2nd May 2021, 2:52 AM
bernborgess
bernborgess - avatar
+ 1
Ok with this I am giving another try @bernborgess
2nd May 2021, 6:52 AM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
@berborgess thank you so so much..it worked
2nd May 2021, 6:57 AM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
by pressing ctrl+z taking input has stopped but the output that I wanted to show that is like this Bach, Johann S. Handel, George F. Bach, Carl P. E. Haydn, Joseph Bach, Johann C. Mozart, Wolfgang A. is not printed.
2nd May 2021, 8:14 AM
Ramisa Fariha
Ramisa Fariha - avatar
2nd May 2021, 4:06 PM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
@Martin I did it again..nothing is unchanged..just the same as usual.. the output comes something like this Johann Sebastian Bach George Frederic Handel Carl Phillipp Emanuel Bach Joseph Haydn Johann Christian Bach Wolfgang Amadeus Mozart ^Z 1. olfgang Amadeus Mozart , Johann Sebastian Bach e. a. o. o. Process returned 0 (0x0) execution time : 108.696 s Press any key to continue. ...I think the code is not properly done in the book.
2nd May 2021, 8:18 PM
Ramisa Fariha
Ramisa Fariha - avatar