```
//Hi,i need to create programm,which takes the user input,determins how many digits in integer
// and than raise this digit to power,what was entered by user too.
//first function noraml,second one to rais to power recursive. So if user enter number
//234,this is 3 digits,so now need recurcively 3 raise to the power .
// This what i got so far program determins the digits from integer,but does not use power
// Power of size number.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<string>
using namespace std;
typedef long double ld;
int countDigits(int number) {
if (number < 10) {
return 1;
}
int count = 0;
while (number > 0) {
number /= 10;
count++;
}
return count;
}
int place(ld,ld);
// testing the countDigits function
int main() {
int num ;
int result;
int exp;
cout << "enter number: "<<endl;
cin >> num;
cout << "Enter exponent: " << endl;
cin >> exp;
int numDigits = countDigits(num);
cout << num << " has " << numDigits << " digits" << endl;
result = place(numDigits,exp);
cout << result;
return 0;
}int place(ld numDigits,ld exp)
{
if(exp >=10)
{
return
numDigits*(place(numDigits,exp-1));
}
else
return 1;
}
```

## Recommended Answers

Jump to PostYour condition at line 45

`if(exp >= 10)`

is wrong. Remeber that any number raise to the power of 0 is 1 but this is not what is embodied by your condition.I would also say you are missing a newline or 2 at line 43.

Also storing exp as …

Jump to PostA couple of other things:

They way you've interpreted the question means that your input number can't be more than 63, since a 64-bit integer(the largest most modern systems will recognize) will max out after that. It makes more sense to raise the input number to the power of the …

## All 8 Replies

Banfa
597
Posting Pro
Featured Poster

tinstaafl
1,161
Posting Maven

aluhnev
0
Junior Poster in Training

tinstaafl
1,161
Posting Maven

aluhnev
0
Junior Poster in Training

aluhnev
0
Junior Poster in Training

tinstaafl
1,161
Posting Maven

Banfa
597
Posting Pro
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.