Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 6.48 #756

Open
haocheng6 opened this issue May 11, 2020 · 0 comments
Open

Exercise 6.48 #756

haocheng6 opened this issue May 11, 2020 · 0 comments

Comments

@haocheng6
Copy link
Contributor

I do not agree with that

the assert would be always true.

In this code, if no word input by the user matches sought, cin will be invalid after the loop, causing the expression cin to be false.

According to page 241,

Therefore, assert should be used only to verify things that truly should not be possible. It can be useful as an aid in getting a program dubugged but should not be used to substitute for run-time logic checks or error checking that the program should do.

As discussed above, it is definitely possible that cin may be evaluated as false after the loop, which is not a bug. So we should not use assert here. Instead, it should be within the program's logic to check if we have found a word matching sought, so an if statement will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant