No result in given interval

Hello!
I created simple program which asks user to enter two whole numbers, afterwards my program prints out all possible cubes in given interval. But when I showed it to my professor he asked me to include one more thing- for example, if user enters numbers 4 and 5 then it says, there are no cubes in this interval. Now I'm stuck because I can't figure out how to include this in my program.

I am learning c++ for one month only, so I am absolute beginner.
Do you have quick solution or at least tips how to complete this program?

Best regards,
J.K

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int ok;
    do
    {
        int m, n, x;
        cout<< "Enter first whole number m= ";
        cin>> m;
        cout<<"Enter second whole number n= ";
        cin>> n;

        if(m>n)
        {
            int a = n;
            n=m;
            m=a;
        }
        for(x=m; x<=n; x++)
        {
            int c =cbrt(x);
            if(c*c*c==x)
            {
                cout<<x<<endl;
                c++;
                x = c;
                break;
            }
        }
        while(x*x*x<=n)
        {
            cout<<x*x*x<< "\n";
            x++;
        }
        do
        {
            cout<<"If you would like to continue: (1) , \nIf you would like to finish: (0)"<<endl;
            cin>>ok;
            if((ok!=1) and (ok!=0))
                cout<<"Enter 1 or 0!"<<endl;
        }while ((ok!=1) and (ok!=0));
    }while (ok==1);
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

int main()
{
    int ok;
    do
    {
        int m, n, x;
        cout<< "Enter first whole number m= ";
        cin>> m;
        cout<<"Enter second whole number n= ";
        cin>> n;

        if(m>n)
        {
            int a = n;
            n=m;
            m=a;
        }
        
        x = m;
        
        do {
            if(x*x*x <= n) {
             cout << x*x*x << endl;
             x++;
            }
            else {
             cout << "There are no cubes in this interval." << endl; 
            }
            
        }while(x*x*x <= n);
        
        do
        {
            cout<<"If you would like to continue: (1) , \nIf you would like to finish: (0)"<<endl;
            cin>>ok;
            if((ok!=1) and (ok!=0))
                cout<<"Enter 1 or 0!"<<endl;
        }while ((ok!=1) and (ok!=0));
    }while (ok==1);
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cmath>
using namespace std;


void cubes( int lower, int higher )
{
   int cr1 = cbrt( lower  );   if ( cr1 * cr1 * cr1 < lower ) cr1++;
   int cr2 = cbrt( higher );
   if ( cr1 > cr2 )
   {
      cout << "No cubes between " << lower << " and " << higher << '\n';
   }
   else
   {
      cout << "The cubes between " << lower << " and " << higher << " are\n";
      for ( int i = cr1; i <= cr2; i++ ) cout << i * i * i << '\n';
   }
}


int main()
{
   cubes( 30, 40 );
   cubes( 27, 27 );
   cubes( 1, 1000 );
}


No cubes between 30 and 40
The cubes between 27 and 27 are
27
The cubes between 1 and 1000 are
1
8
27
64
125
216
343
512
729
1000
Topic archived. No new replies allowed.