Question: Consider the following two code fragments for counting spaces and newlines: // Version 1 while (cin.get(ch)) // quit on eof { if (ch == '
Consider the following two code fragments for counting spaces and newlines:
// Version 1
while (cin.get(ch)) // quit on eof
{
if (ch == ' ')
spaces++;
if (ch == '\n')
newlines++;
}
// Version 2
while (cin.get(ch)) // quit on eof
{
if (ch == ' ')
spaces++;
else if (ch == '\n')
newlines++;
}
What advantages, if any, does the second form have over the first?
Step by Step Solution
3.33 Rating (156 Votes )
There are 3 Steps involved in it
The advantages are 1 Congruence The for loop of versio... View full answer
Get step-by-step solutions from verified subject matter experts
