why does my program end when it's an infinite loop?

I wanted to make an infinite loop where I take the number one and divide it by 2, it would keep doing this as long as the resulting number is a real number. I know that you can keep dividing a number an infinite amount of times but when I run my program it ends at a really small number rather than go on forever like if you were to make a loop where int=1 and while(int==1) the program just repeats and never ends

here is my program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
    double num=1;
    
    while(num>0)
    {
    cout << num << ", \n";
    num=num/2.0;
    }
    
    system("PAUSE");
    return 0;
}


inside the while {} how can I tell it to repeat as long as num equals a real number?

Thank you.
Last edited on
To be able to keep going on forever, you would need to be able to store a number with infinite precision, you can't do that, it would take an infinite amount of space. Eventually, it will just round down.
Topic archived. No new replies allowed.