# Thread: Newbie help with expontential program

1. The fact that you don't want to do 5*3*3, but rather 5*5*5, to get five cubed. You don't multiply by the exponent, but by the base.

2. I understand that 5 ^ 3 = 5 * 5 * 5.

I don't know how to tell C that 5 * 5 *5 is.

3. Code:
`base *= exp;`
multiples by the exponent. To multiply by the base, you need to multiply by the base:
Code:
`base *= base;`
EDIT: And of course I mean result *= base, not base *= base.

4. If I say
base = exp won't it override by value for scanf in the for statement?

5. Not in the for statement in the

Code:
`{ }`
below the for statement

6. Originally Posted by BSmith4740
If I say
base = exp won't it override by value for scanf in the for statement?
Yes. Fortunately for you, you don't want to say base = exp at any point along the way. You do want to set result=base after reading in what the base is.

7. That created an infitite loop. It won't stop. What the heck?

8. I need a for statement based on the exponent to make it stop?

Code:
```#include <stdio.h>
2
3    int main(void)
4    {
5   float base, exp, product, a;
6   double result;
7
8
9
10
11
12
13 printf("Enter base\n");
14  scanf("&#37;f",&base);
15  printf("Enter exponent\n");
16  scanf("%f",&exp);
17
18  printf("The exponent is %f\n",exp);
19  printf("The base is %f\n",base);
20  result = 0;
21 product = 1;
22  for( a = 1; a <= base; a++)
23  {
24
25  base *= base;
26  printf("The exponent is %f\n",exp);
27  printf("The base is %f\n",base);
28
29
30  printf("The variable A is equal to %f\n",a);
31
32
33
34  result = base *  exp;
35  printf("Result is %f\n",result);
36  if ( 0 == product - base)
37  return base;
38
39  }
40
41  return 0;
42  }```
That is pretty cool though.

9. Originally Posted by BSmith4740
That created an infitite loop. It won't stop. What the heck?
What did?

10. Code:
``` for( a = 1; a <= base; a++)
23  {
24
25  base *= base;```
Where does exponent come into play?

I entered 5^3 and it just keeps crawling at 100 mph.

I changed base from exp in the for statment and added
line 25

11. Do I need two four loops for this?

12. Originally Posted by BSmith4740
Code:
``` for( a = 1; a <= base; a++)
23  {
24
25  base *= base;```
Where does exponent come into play?

I entered 5^3 and it just keeps crawling at 100 mph.

I changed base from exp in the for statment and added
line 25
And you changed the for-loop why? The point of the exponent is to count the number of multiplies. What the for loop does is multiply. Therefore you need to use the exponent to count in the for-loop. And look at the edit to my point above.

13. Thanks tabstop,

Drop me a line on the instant messages with a paypal account and I will send you a little something for your trouble. Apprciate the help man. Now if I can just code this in my larger program I should be in business.

14. I mean the private messages. Everyone needs a little help with gas these days.