Optimizing code for UVAJ 573 The Snail
So first things first, your code looks terrible.


Use real names for your variables that are understandable without any further reading, e.g. instead of fu you could use fatique.
Your variable success is a boolean so make it one.
You should introduce a factor for the fatique rather than subtracting it. That would make the code simpler. Also your failure is most likely because the snail takes so much time to slide back down. So rather than checking for snailHeight &gt; 0 check for heightSlid &gt; fatique * heightClimbed

size_t numDays = 0;
double snailHeight = 0.0;
double fatique = 1.0;
bool fail = false;
while (true) {
    numDays++;
    snailHeight += fatique * heightClimbed;
    fatique *= 0.9;
    if (heightSlid &gt; fatique * heightClimbed) {
        fail = true;
        break;
    } else if (snailHeight &gt; heightWell) {
        break;
    }

    snailHeight -= heightSlid;
}

if (fail) {
    std::cout &lt;&lt; "failure\n";
} else {
    std::cout &lt;&lt; "success on day " &lt;&lt; numDays &lt;&lt; "\n";
}