Help in syntax void function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jendrin
    New Member
    • Jul 2007
    • 11

    Help in syntax void function

    (Regula falsi metod. To calculate the root using 4 iterations)
    I need the user to pick from problem a, b or c wherein every problem has different initial guesses.ex( prob. a Xd=1 Xu=2, prob. b Xd=2 Xu=3)
    same process for all problems. And also i want to show all the values of Xd,Xu,Xr,d,u,r for the 4 iterations in tabular form.What i have done so far is this:

    void falsi(double& fd, double& fu, double& fr, double d, double u, double r)
    {
    fd=sin(d)+cos(1 +d*d)-1;
    fu=sin(u)+cos(1 +u*u)-1;
    r=((u*fd - d*fu) / (fd - fu));
    fr=sin(r)+cos(1 +r*r)-1;
    }

    void eq(int x, int y)
    {
    d=1;
    u=2;
    cout<<"The value of Xd=1 and Xu=2\n";
    for (i=4;i<5;i++)
    {
    falsi(fd,fu,fr, d,u,r)
    if (fr>0 && fd>0)
    {
    r=d;
    else
    r=u;
    }
    cout<<fd<<fu<<f r<<d<<u<<r;
    }

    int main
    {
    cout<<"choose letter a, b, or c";
    cin<<z; // is this correct??
    if (z==a)
    {
    void eq(1,2);
    if(z==b)
    {
    void eq(2,3);
    else
    void eq(1,4);
    }
    }

    // Is this correct?
    Btw, where can i download MSdev C++ version 5.0?
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by jendrin
    (Regula falsi metod. To calculate the root using 4 iterations)
    I need the user to pick from problem a, b or c wherein every problem has different initial guesses.ex( prob. a Xd=1 Xu=2, prob. b Xd=2 Xu=3)
    same process for all problems. And also i want to show all the values of Xd,Xu,Xr,d,u,r for the 4 iterations in tabular form.What i have done so far is this:

    void falsi(double& fd, double& fu, double& fr, double d, double u, double r)
    {
    fd=sin(d)+cos(1 +d*d)-1;
    fu=sin(u)+cos(1 +u*u)-1;
    r=((u*fd - d*fu) / (fd - fu));
    fr=sin(r)+cos(1 +r*r)-1;
    }

    void eq(int x, int y)
    {
    d=1;
    u=2;
    cout<<"The value of Xd=1 and Xu=2\n";
    for (i=4;i<5;i++)
    {
    falsi(fd,fu,fr, d,u,r)
    if (fr>0 && fd>0)
    {
    r=d;
    else
    r=u;
    }
    cout<<fd<<fu<<f r<<d<<u<<r;
    }

    int main
    {
    cout<<"choose letter a, b, or c";
    cin<<z; // is this correct??
    if (z==a)
    {
    void eq(1,2);
    if(z==b)
    {
    void eq(2,3);
    else
    void eq(1,4);
    }
    }

    // Is this correct?
    Btw, where can i download MSdev C++ version 5.0?
    You have some syntax errors.
    [CODE=cpp]void eq(int x, int y)
    {
    d=1;
    u=2;
    cout<<"The value of Xd=1 and Xu=2\n";
    for (i=4;i<5;i++)
    {
    falsi(fd,fu,fr, d,u,r)
    if (fr>0 && fd>0)
    {
    r=d;
    else
    r=u;
    }
    cout<<fd<<fu<<f r<<d<<u<<r;
    }[/CODE]
    You call falsi with fd, fu, fr, u, and r, but you never declared fd, fu ,fr, or r. Also, you never use x and y which are passed into the function.
    [CODE=cpp]if (fr>0 && fd>0)
    {
    r=d;
    else
    r=u;
    }[/CODE]
    The brace on that if is wrong. It should be like this:
    [code=cpp]
    if (fr > 0 && fd > 0)
    {
    r = d;
    }
    else
    {
    r = u;
    }
    [/code]
    You also did that in main.
    [CODE=cpp]int main
    {
    cout<<"choose letter a, b, or c";
    cin<<z; // is this correct??
    if (z==a)
    {
    void eq(1,2);
    if(z==b)
    {
    void eq(2,3);
    else
    void eq(1,4);
    }
    }[/CODE]
    You never declared 'z' when you use it with cin. Also, you are checking z with the variable 'a'. You want to check it against the value 'a'. Also, you are calling your functions wrong. Delete the void before the call.
    [CODE=cpp]int main
    {
    char z;
    cout<<"choose letter a, b, or c";
    cin<<z; // is this correct??
    if (z=='a')
    {
    eq(1,2);
    }
    else if (z=='b')
    {
    eq(2,3);
    }
    else
    {
    void eq(1,4);
    }
    }
    }[/CODE]
    Hope that helps.

    PS And please put your code in code tags, it makes it easier to read.

    Comment

    • jendrin
      New Member
      • Jul 2007
      • 11

      #3
      thx so much phython! sorry i'm just new here and i dont know how to create tags..
      what about void(int x,int y)? i didn't quite understand whats wrong with it..can you clear it up more?thx so much again!!

      btw, will this program work?

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by jendrin
        thx so much phython! sorry i'm just new here and i dont know how to create tags..
        what about void(int x,int y)? i didn't quite understand whats wrong with it..can you clear it up more?thx so much again!!

        btw, will this program work?
        The code tags are just [ c o d e = c p p ] [ / c o d e ] without the spaces.

        Your function takes two integers, x, and y. You never use them in the function. What are you trying to do?

        Comment

        Working...