Thread: Newbie help with expontential program

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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. #17
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    I understand that 5 ^ 3 = 5 * 5 * 5.

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

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.
    Last edited by tabstop; 06-11-2008 at 05:53 PM.

  4. #19
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    If I say
    base = exp won't it override by value for scanf in the for statement?

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    Not in the for statement in the

    Code:
    { }
    below the for statement

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by BSmith4740 View Post
    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. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    That created an infitite loop. It won't stop. What the heck?

  8. #23
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    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. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by BSmith4740 View Post
    That created an infitite loop. It won't stop. What the heck?
    What did?

  10. #25
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    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. #26
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    Do I need two four loops for this?

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by BSmith4740 View Post
    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. #28
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    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. #29
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    I mean the private messages. Everyone needs a little help with gas these days.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie looking for hints on first audio program...
    By BrownB in forum Game Programming
    Replies: 2
    Last Post: 07-13-2005, 07:25 AM
  2. Newbie program - improvements?
    By -JM in forum C++ Programming
    Replies: 9
    Last Post: 06-26-2005, 06:53 PM
  3. newbie needs help with C++ program
    By cyba in forum C++ Programming
    Replies: 9
    Last Post: 06-25-2004, 02:41 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM