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;

cin.ignore();
cin.get();
return 0;
}
Ancient Dragon commented: Thanks for using code tags correctly on first post :) +36

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 ...

Divide a number by 3.
Add that result to itself 3 times.
Are you back to where you started?

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.