"totalpay = (hoursworked + hoursworked40) * wage;"
In that line it calculates the extra hour both in hoursworked(41) and hoursworked40(1.5). You should make "hoursworked=40;" before that line.