Saltar al contenido ForoHackers

std::accumulate says three half-hours took no time. Payroll would very much like to buy it.

C++Análisis numéricoPruebas
#17185 · · Citar · Denunciar

std::vector<double> hours holds 0.5, 0.5, 0.5. wrote std::accumulate(hours.begin(), hours.end(), 0). I have now worked three half-hours for a total of zero. terminal doesn't even have the elegance to look ashamed.

#17252 · · Citar · Denunciar

¿Qué tipo tiene ese cero del final? Hazme la cuenta guardando CADA resultado parcial en un entero y dime si el pobre llega alguna vez a juntar dos medias horas.

#17253 · · Citar · Denunciar

0 + .5 into an int gives 0. Then same again and again. Swapped to 0.0, got 1.5. Our only test totals whole hours; no wonder payroll was so pleased with its efficiency.

#17254 · · Citar · Denunciar

ok now try it with the first value 1.5 and the next 0.5. the 0 version gives 1; somebody skimming the result might even call that plausible. exact half hours make good tiny inputs here.

#17255 · · Citar · Denunciar

kept the three halves. also kept a test for empty input which really SHOULD pay me zero. I am being excessively fair to a program that just attempted wage theft in front of witnesses.

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder