0

Just want to print the total fare and passenger once at last

https://code.sololearn.com/coGSwukhEI57/?ref=app

22nd Jan 2023, 5:03 AM
Jay Ravidas
Jay Ravidas - avatar
1 Answer
+ 4
Line 9: Use while( sc.hasNextDouble() ) instead of while( true ) That way the loop only runs while there is input that can be converted to `double` type. Use of while( true ) in a non interactive environment like SoloLearn Code Playground is not possible, all inputs must be provided upfront. Even running in an IDE, a while( true ) loop doesn't make much sense here, no one will type inputs in for the code infinitely. Line 22: The calculation always yields 0.0 because <f> was initialized by zero on each loop round. I think you need to revise that. Line 25: You are incrementing <tp> by one, using `++` operator, so there's no need for reassignment. Just write like that tp++;
22nd Jan 2023, 6:34 AM
Ipang