segmentation fault

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freddyjones39
    New Member
    • Feb 2008
    • 5

    segmentation fault

    I am a beginner (very much so) in computer programming, I use a gcc compiler.
    The following program is not yet finished, but is at a stage that it should atleast run. It compiles fine, and asks for, and execpts value "b", but then geves a segmentation error message, and I have no idea why. Any help would be appretiated.


    [code=cpp]
    #include<iostre am>
    #include<iomani p>
    using namespace std;

    double get_input (char note[], double min);
    //Requires: A name of the item.
    //Promises: "a" (a weight to length ratio).

    double calc_a (double b, double l, double g);
    //Requires: Previously calculated "a".
    //Promises: Total a of cable.

    int main()
    {
    cout<<"main"<<e ndl;
    double b=get_input("b" ,0);

    double l=get_input("l" ,2*b);

    double g=get_input("g" ,0);

    double a=calc_a(b,l,g) ;
    cout<<"a is_"<<a<<endl;
    }

    double get_input (char note[],double min)
    {
    cout<<"input "<<note<<en dl;
    cin>>note;
    return 1;
    }
    double calc_a (double b, double l, double g)
    {
    double a = get_input("g",0 );
    while ((l*a-g*(pow(1+a,b)-1))!=0)
    {
    a=(a-(l*a-g*(pow(1+a,b)-a)))/(l-g*b*(pow(b+1,b-1)));
    }
    return a;
    }[/code]
    Last edited by sicarie; Feb 23 '08, 10:20 PM. Reason: Please use the code tags provided (they are [code=<c or cpp>] your code here and[/code]. Thanks
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    You do know that you are trying to use a function that you haven't defined yet, right? I'm referring to pow(), when you haven't included the cmath library?

    Hmm, so I haven't seen get_input() before (or if I has, it was a very long time ago), why not just use cin?

    Comment

    • freddyjones39
      New Member
      • Feb 2008
      • 5

      #3
      Thanks for the speedy reply. I think I got it figured out.

      Comment

      • freddyjones39
        New Member
        • Feb 2008
        • 5

        #4
        I'm just trying to learn how to use functions.

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by freddyjones39
          Thanks for the speedy reply. I think I got it figured out.
          Awesome, care to post what you figured out, just in case someone else has the same issue?

          Comment

          • freddyjones39
            New Member
            • Feb 2008
            • 5

            #6
            I re-wrote it completely, and the only thing that I can see that is different is the boolean expression after the while statement, and also my calc_a formula was wrong.
            Last edited by freddyjones39; Feb 23 '08, 11:33 PM. Reason: Poor answer

            Comment

            Working...