No using C++?
Your original code is curiously close to
http://www.programiz.com/c-programming/examples/check-armstrong-number
That (linked) version is actually a better starting point. It does not mix input with the computation.
The first thing is to move the code into a function. From
1 2 3 4
|
int main() {
// code
return 0;
}
|
into:
1 2 3 4 5 6 7 8
|
void foo() {
// code
}
int main() {
foo();
return 0;
}
|
Next, remove the user input code from the foo(), return it to the main() and pass the number to foo as function argument.
1 2 3 4 5 6 7 8 9 10
|
void foo( int number ) {
// code
}
int main() {
int n = 0;
// get value of n from user
foo( n );
return 0;
}
|
Then you should figure out how to make the program to repeatedly ask and evaluate numbers. That repetition has nothing to do with the evaluation of any single number.
As already pointed out "
An Armstrong number is an N-digit number that is equal to the sum of the Nth powers of its digits." I did not know that before. You did not tell that in the first post. Why should we have to look up the basics of your problem?
Anyway. number of digits is easy to calculate. It is better to have a separate function for that.
Likewise, integer version of pow() is easy to write and use.
You do need those two operations, because you input is not limited to 3-digit values.
PS. Your original code does not use anything from header <math.h>. Do not include headers that you don't need.