Expansions

This is a discussion on Expansions within the C++ Programming forums, part of the General Programming Boards category; I'm writing a program to compute a sort of binomial expansion. It inturn uses a factorial function. But there is ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    Exclamation Expansions

    I'm writing a program to compute a sort of binomial expansion. It inturn uses a factorial function.

    But there is some errors within the program which i just cant figure out. Help me plzzz. <<snipped email>>. I really need the help
    the program is as below:

    Code:
    #include <iostream.h>
    #include <math.h>
    #include <conio.h>
    
    int factorial (int num)
    {
     int result=1;
     cout<< "Enter The Number Of Factorials To Be Used:";
     cin>>num;
     for (int i=1; i<=num; ++i)
        result=result*i;
     return result;
    }
    
    
    void result ()
    
    {
    int r,n;
    float x;
    float m;
    
    cout<< "THE NUMBER OF TERMS AND AND THE NUMBER OF FACTORIALS SHOULD BE EQUAL\n\n";
    cout<< "Enter The N Number Of Terms To Be Used:";
    cin>> n;
    cout<< "Enter The Value Of X:";
    cin>>x;
    m = 0;
    
    
    for (r=0; r<=n; r++)
    {
    m == x^r/r*factorial;
    }
    cout<< "Summation ="" ";
    cout<< m;
    
    getch();
    }
    Last edited by Salem; 11-16-2007 at 02:48 PM. Reason: You posted it here, you read it here.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Well your first problem seems to be trying to use the ^ operator as "raise to power of", and it isn't that at all. It's the bitwise exclusive-or operator.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I wonder how many boards mutty posted this to, seeing as he has no time check each for a reply.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    This looks like the work of someone who just types in whatever random sequence of symbols, keywords, and variable names come to mind, and simply prays for a working program.

    If you want to program you actually have to learn what all those symbols and keywords do. You need to sit down with a good book and actually spend time learning from it.
    Look that may sound harsh, but you yourself know that you barely have a clue what you're doing beyond how to cout or cin something. If you can't be bothered spending the time to learn it then I can't be bothered helping.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21