- Joined
- Sep 23, 2006
- Messages
- 4
- Reaction score
- 0
Hello,
I am trying to find the smallest 'delta' value that makes the following equation evaluate to TRUE.
***Let x be a double***
x + 'delta' != x
This is the code I wrote. Can somebody help me figure out why it stops after 1 execution of the WHILE loop?
#include <iostream>
using namespace std;
void main()
{
int i=1;
double x=1;
while (x != (x + (1/i)))
{
i++;
}
cout << "I equals " << i << endl;
//cout << "Delta equals " << 1/(i-1) << endl;
}
Result: I equals 2
****This next snippet stops after 1 execution as well (different code, same math). LOL.****
void main()
{
int i=1;
double x=1;
double y = x + (1/i);
while (x != y)
{
i++;
y = x + (1/i);
}
cout << "I equals " << i << endl;
//cout << "Delta equals " << 1/i << endl;
}
RESULT: I equals 2
Thanks in advance.
I am trying to find the smallest 'delta' value that makes the following equation evaluate to TRUE.
***Let x be a double***
x + 'delta' != x
This is the code I wrote. Can somebody help me figure out why it stops after 1 execution of the WHILE loop?
#include <iostream>
using namespace std;
void main()
{
int i=1;
double x=1;
while (x != (x + (1/i)))
{
i++;
}
cout << "I equals " << i << endl;
//cout << "Delta equals " << 1/(i-1) << endl;
}
Result: I equals 2
****This next snippet stops after 1 execution as well (different code, same math). LOL.****
void main()
{
int i=1;
double x=1;
double y = x + (1/i);
while (x != y)
{
i++;
y = x + (1/i);
}
cout << "I equals " << i << endl;
//cout << "Delta equals " << 1/i << endl;
}
RESULT: I equals 2
Thanks in advance.
Last edited: