shadowdogg
11-01-2007, 12:25 AM
Hi there,
I desperately need help on a program I need to do.
A user will enter a value and a power.
This will need to work out value^power.
Completely stuck - unsure how to work out the problem.
It is part of a debugging exercise and I have just been randomly changing the stuff to see if i can work out the answer and have failed miserably, spending 5 hours on this little problem.
This is the code i have been using and it is all wrong. Don't understand how i can get it to do num * pow, pow times.
Please give me some assistance in the direction I need.
Thanks.
int answer = num;
for(int i = 1; i < pow; i++) {
answer *= i;
System.out.println("The value of num inside the loop is " + num);
System.out.println("The value of pow inside the loop is " + pow);
}
System.out.println("The end value of answer is" + answer);
System.out.println("The end value of pow is" + pow);
System.out.println("The end value of num is" + num);
System.out.println(num + " to the power of " + pow + " is " + answer);
I desperately need help on a program I need to do.
A user will enter a value and a power.
This will need to work out value^power.
Completely stuck - unsure how to work out the problem.
It is part of a debugging exercise and I have just been randomly changing the stuff to see if i can work out the answer and have failed miserably, spending 5 hours on this little problem.
This is the code i have been using and it is all wrong. Don't understand how i can get it to do num * pow, pow times.
Please give me some assistance in the direction I need.
Thanks.
int answer = num;
for(int i = 1; i < pow; i++) {
answer *= i;
System.out.println("The value of num inside the loop is " + num);
System.out.println("The value of pow inside the loop is " + pow);
}
System.out.println("The end value of answer is" + answer);
System.out.println("The end value of pow is" + pow);
System.out.println("The end value of num is" + num);
System.out.println(num + " to the power of " + pow + " is " + answer);