Raise the first digit to the power of the second digit.

I'm having trouble with my homework assignment because I'm stuck on this problem:
If the number is a two digit number, then raise the first digit to the
power of the second digit.
Does anyone know how to make a second digit of a two digit number the power of the number's first digit.

Hint: You will need to use modulus to help break apart the number.
Well yes I have modules in my code, one for each section but do you mean a module for each digit or something?
Maybe this will help this code breaks apart the number into 2 separate numbers then raises the first digit to the power of the second. I'm not sure if your assignment is to just do this or if you should keep what was originally the second number. Currently, 26 becomes 64 but I'm not sure if your assignment only wants the first number to change so 26 would become 646

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	int num, temp1, temp2, temp3;

	cout << "Input number: ";
	cin >> num;

	temp1 = num / 10;
	temp2 = num % 10;


	//num = 0;
	
	temp3 = pow(temp1, temp2);

	cout << num << endl;


If you would like it to add to be 646 then add num = temp3 * 10 + temp2; after pow
Last edited on
Yeah, I think this might help let me give it a try thank you.
I think it actually worked.

[int choice5(int& temp1, int& temp2, int& randomNum)
{
temp1 = randomNum / 10;
temp2 = randomNum % 10;

randomNum = pow(temp1, temp2);

cout << randomNum << endl;
return randomNum;
}][/code]
This is the function I wrote based on my code, I'm sorry if it doesn't appear on the forum the way it should I'm new in this website.
Ya, your function looks good. For using the website when using the code tags, put the code in between the code brackets Ex: [cod_e] Put code here [/code]
Thanks that helps a lot!
Topic archived. No new replies allowed.