+ 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.
11 ответов
+ 2
Can you show the code how it is now? I may find the bug.
+ 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
+ 1
You wanna read a whole line instead of just a word. Use getline (cin,name); instead of cin>>name;
+ 1
ok thanks @bernborgess
+ 1
@bernborgess I have tried your way..still doesn't fix the problem
+ 1
Also if you use while to get an unlimited amount of input your last line should be just a ctrl Z key
+ 1
Ok with this I am giving another try @bernborgess
+ 1
@berborgess thank you so so much..it worked
+ 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.
+ 1
https://code.sololearn.com/c51A1A22A1A2/?ref=app this is the code
+ 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.