[Solved] wrong answer from boolean function [closed]


Learn how to debug. If you cannot trace line-by-line through your code, then try to keep some kind of log.

For now at least output this to the console.

In your case
1. Verify the input file opened successfully
2. Print out each gift as you read it in.

would be a good way to start.

If you want to be able to put multiple log statements in and then remove them later, you can use a macro which can be turned off in one place.

Logging is a fairly tricky skill to be effective for large projects which continue to run into production, however you should learn how to do it in the short-term to debug your program.

We here cannot even see what is in your input file. This is why people are downvoting your question.

Ok: Now you’ve told me your issue is you need to trim whitespace from the front of each string you read in.

There are multiple ways to do that but

trimmed = s.substr( s.find_first_not_of(" \n\r\t" ) );

will probably work for now.

However my original answer still holds: please learn to debug. If you’d outputted the strings as you read them in, you would have seen these leading spaces.

2

solved wrong answer from boolean function [closed]