Shortest road trip

why we write 2 times ch=cin.get() in the code of shortest road trip problem can you explain reasons

Hello @sudiptakdas,

The first ch=cin.get() is used to read the first character and
the other ch=cin.get() (written inside the loop) is used to read the remaining characters

  1. As you are not initialising the ch with any value, so it is possible that it might contain ‘\n’ as junk value.
    In this case, the loop will directly terminate.
    Thus, to prevent this we are reading the first character before the loop begins.

Hope, this would help.
Give a like, if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.