The C++ code is calculating electricity bills by getting input for previous and current readings, calculating units used and bill amount, and displaying the output. To prevent negative numbers from being accepted, the code checks if the current input is negative, and if so, sets it to 0, which will cause the do-while loop in main to end.