, 6.
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main() {
int i = 10;
int k = 1;
for(;;)
{
float prev = 0.0f;
for(int j = 1; j <= i; ++j)
{
stringstream ss;
ss << "0.";
ss << setfill('0') << setw(k) << j;
float next;
ss >> next;
if(prev == next) return 0;
prev = next;
}
cout << "Works for " << k << " places" << endl;
i *= 10;
k++;
}
return 0;
}
1. Set precision to 1 place after decimal
2. Compare 0.0 with 0.1, 0.1 with 0.2 .... 0.8 with 0.9 and 0.9
with 1.0, if any of these are equal (not distinguish), exit.
Otherwise print Works for 1 place.
3. Set precision to 2 places after decimal
4. Compare 0.00 with 0.01, 0.01 with 0.02 .... 0.98 with 0.99 and 0.99
with 1.00, if any of these are equal (not distinguish), exit. Otherwise
print Works for 2 places.
5. Repeat similar steps for 3 and more digits unless you exit