i am in beg c++ and my instructor is asking me to find "some other combination that also does not work! Your loop should prove something similar for values other than 10 cycles, steps of 0.1, and a sum of 1."

i found 1 combination, which is in my program below. I dont truly understand what round off errors are and feel as though i cant create another loop that doesnt work. does anyone have any ideas? any suggestion would be truly helpful.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
  double x;
  for (x = 0; x != 1; x += 0.1)
    cout << x << endl;

return 0;
Votes + Comments
Thanks for using code tags correctly on first post :)
8 Years
Discussion Span
Last Post by xiikryssiix

If you are looking for code that fails, this doesn't work either. for(int x = 1.0; x != 0; x -= 0.1) There are lots of ways to make floats fail due to rounding errors. For example x = 1; x = x / 3; You think the result would be 1/3 right? Wong. Its 0.33333333333 ...


are Round Off Errors like limiting values (calculus talk wise)?
like the number can get super close to an integer, but not truly become that value?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.