The following code snippet transforms names into telephone book foremat.
To get it to work properly I had to introduce the 'if' statement in line 3 of the loop as well as pressing Ctrl+Z to quit after entering the last name. Without the 'if' statement it keeps on printing the last word entered until n==35. I have tried using 'while(cin>>wor d)' and placing 1st and 3rd lines in { } but no success. How can I get rid of the 'if' statement and have the code work properly?
Thanks in advance if you can help.
Code:
while(n<35) { cin>>first>>middle>>last; if(first=="z") break; middle=middle.substr(0,1); word=last+", "+first+" "+middle+"."; name[n]=word; n++; }
Thanks in advance if you can help.
Comment