Help about program for cube

Hi all i need to make program to check did typed three digit number like(357) is equal to cube of his digits.
Sorry for bad English.
Last edited on
No one is going to do your homework for you.

Think about the problem. What do you need to solve it?

The first thing is that you need a way to cube a number. Can you write the code that will do that?
Last edited on
I know how to write three digit number but i dont know how to find cube and check are they equal
What is 3 cubed?
Cubes is n*n*n ex(2*2*2) and three is three digits number ex(256)
What you need to do is do that in reverse, i.e. If you were to enter 27, your code would do the mathematics and check if its a valid cube or not.


Take a look at the function cbrt : http://www.cplusplus.com/reference/cmath/cbrt/?kw=cbrt

Lets say I enter 27 (the result of LowestOne's post) and I want to check if thats a cube..

Do cbrt(27) which will give you the result of 3, then use that return value to perform your n x n x n, and if the result of that calculation matches what the user entered then we have ourself a cube.




You need to split the 3-digit number into it's component digits. To do that notice that number % 10 give you the least significant digit of an integer and number / 10 drops the least significant digit. Figure out how to combine these to extract the 3 digits into 3 separate variables. I'll call them a, b, and c.

Once you have a b and c, you can check if the sum of their cubes equals the original number.
I am total beginner at c++ i need this for school if someone can help me precizily with code.
Like I said, no one is going to do your homework. The best we can do is to help you think through it.

I'm still unsure of what you are trying to do though, you want to check if 3^3 + 5^3 + 7^3 equals 357?

i dont know how to find cube
Cubes is n*n*n ex(2*2*2)


See, you do know how to do it. You have your first function:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int cube( int x )
{
  return x * x * x;
}

int main( void )
{
  cout << "3 cubed equals " << cube( 3 ) << '\n';
  return 0;
}

To learn more about functions, http://www.cplusplus.com/doc/tutorial/functions/

Would you mind showing me the code you wrote to collect the data from the user?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main()
{
int firstnumber,secondnumber,thirdnumber;
cout<<"Put first number"<<endl;
cin>>firstnumber;
cout<<"Put second number"<<endl;
cin>>secondnumber;
cout<<"Put third number"<<endl;
cin>>thirdnumber;
cout<<"Three digits number is:"<<firstnumber<<secondnumber<<thirdnumber<<endl;
}

I have this and I don't know what to do next.
Sorry for double post. Anyone to help i need this for tommorow.
Hi all.
I want to help you, so JUST(its really bad algorithm! it cant work for big numbers and really its terrible! don't use it!) for tomorrow lets make a code that have and for and it have and int like i and it will +1 each cycle and check if i^3 is equals to the given number or no.
But as the others said, the better way to solve this problem, is make the given number to the prime numbers(3 prime number) and see if the ^3 of them is equal to the given number or not, i think you can use goldenbakh idea too, search it on a search engine and see the result.
If my idea is not true please someone tell it, now i cant make focus on the program because ... . :D
Have Nice Life.

EDIT: I think i didn't get your question, so :D i'm sorry about it if i cant help you
Last edited on
Well now you can easily get the entire number by multiplying firstnumber by 100, secondnumber by 10, and then adding those to thirdnumber. Then it's just a matter of comparing the cubes to that.
Topic archived. No new replies allowed.