Consider the following two code fragments for counting spaces and newlines: // Version 1 while (cin.get(ch)) //

Question:

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?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

C++ Primer Plus

ISBN: 9780321776402

6th Edition

Authors: Stephen Prata

Question Posted: