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?
#include <iostream>
#include <cmath>
usingnamespace 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;
}
#include <iostream>
usingnamespace 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;
}