CrazyEngineers
  • PuneetVerma
    PuneetVerma

    MemberAug 26, 2014

    Help with C++

    Can you please rectify error in this program.

    I am not getting output of last three cout statements.
    #include 
    #include 
    using namespace std;
    float vel (float, float);
    int main ()
    {
    float p,hg,h,d,w,qc,qr,bs,ac,wpr,s,r,v,ss1,ss2,dl=8.0,b=1.5;
    cout<<"Enter Power Potential in MW = ";
    cin>>p;
    cout <<"Enter Gross Head in meters = ";
    cin>>hg;
    float x,y,z;
    cout<<"\nFor Lined Channel ..press 0\nFor Unlined Channel ..press 1\n";
    cin>>x;
    cout<<"\nFor Channel in Cutting ..press 2\nFor Channel in Filling ..press 3\n";
    cin>>y;
    cout<<"\nFor Power Channel ..press 4\nFor Head Race Channel ..press 5\n";
    cin>>z;
       if (x==0 && y==0)
       {cout<<"Channel is Lined and Section is in Cutting\n";
       ss1=1, ss2=1;
       }
       else if (x==0 && y==1)
       {cout<<"Channel is Lined and Section is in Filling\n";
       ss1=1, ss2=1.5;
       }
       else if (x==1 && y==0)
       {cout<<"Channel is Unlined and Section is in Cutting\n";
       ss1=1, ss2=1.5;
       }
       else
       {cout<<"Channel is Unlined and Section is in Filling\n";
       ss1=1, ss2=2;
       }
         if (z=4)
         {cout<<"Power Channel\n";
         bs=(1/200);
         }
         else
         {cout<<"Head Race Channel";
         bs=(1/400);   
         }
    h=0.9*hg;
    qr=(p*1000)/(9.81*0.80*h);
    qc=0.0;
    d=0.0;
    while(qc
        
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • [Prototype]

    MemberAug 26, 2014

    I didn't checked it for error but that's very ugly code for sure. No proper indentation, meaningless variable names, "{a=" -> Who even taught you to do this? 😲

    You should rather re-write it with proper coding etiquette. That will help for you and others to identify what you're trying to do and what is going wrong.
    Are you sure? This action cannot be undone.
    Cancel
  • PuneetVerma

    MemberAug 26, 2014

    No No. This has been written correctly. The problem is it might look weird to you because it is design of structures of civil and mechanical in C++
    Are you sure? This action cannot be undone.
    Cancel
  • harmanveer kaur

    MemberAug 26, 2014

    #include <iostream.h>
    #include <math.h>
    float vel (float, float);
    int main ()
    {
    float p,hg,h,d,w,qc,qr,bs,ac,wpr,s,r,v,ss1,ss2,dl=8.0,b=1.5;
    cout<<"Enter Power Potential in MW = ";
    cin>>p;
    cout <<"Enter Gross Head in meters = ";
    cin>>hg;
    float x,y,z;
    cout<<"\nFor Lined Channel ..press 0\nFor Unlined Channel ..press 1\n";
    cin>>x;
    cout<<"\nFor Channel in Cutting ..press 2\nFor Channel in Filling ..press 3\n";
    cin>>y;
    cout<<"\nFor Power Channel ..press 4\nFor Head Race Channel ..press 5\n";
    cin>>z;
    if (x==0 && y==0)
    {cout<<"Channel is Lined and Section is in Cutting\n";
    ss1=1, ss2=1;
    }
    else if (x==0 && y==1)
    {cout<<"Channel is Lined and Section is in Filling\n";
    ss1=1, ss2=1.5;
    }
    else if (x==1 && y==0)
    {cout<<"Channel is Unlined and Section is in Cutting\n";
    ss1=1, ss2=1.5;
    }
    else
    {cout<<"Channel is Unlined and Section is in Filling\n";
    ss1=1, ss2=2;
    }
    if (z==4)// modified
    {cout<<"Power Channel\n";
    bs=(1/200);
    }
    else
    {cout<<"Head Race Channel";
    bs=(1/400);
    }
    h=0.9*hg;
    qr=(p*1000)/(9.81*0.80*h);
    qc=0.0;
    d=0.0;
    while(qc<qr)
    {
    d=d+0.005;
    if (d<=4.0)
    { w=d;
    ac=w*d;
    wpr=(w+(2*d));
    }
    else if (d<=8.0)
    { w=2*d;
    ac=w*(w+ss1*d);
    wpr= (w+ (2*d*sqrt(pow(ss1,2.0)+1)));
    }
    else
    { w=2*d;
    ac=(w+ss1*dl)*dl+(w+2*ss1*dl+2*b+ss2*(d-dl)*(d-dl));
    wpr=(w+(2*dl*sqrt(1+pow(ss1,2.0))+(2*b)+(2*(d-dl)*sqrt(1+pow(ss2,2.0)))));
    }
    r=ac/wpr;
    v=vel(r,bs);
    qc=ac*v;
    }
    cout<<"Depth of the channel = "<<d<<endl;
    cout<<"Width of the channel = "<<w<<endl;
    cout<<"Discharge of channel = "<<qc<<endl;
    return 0; //modified
    }
    float vel (float r,float bs)
    {
    float n=0.018,vc;
    vc=(1/n)*sqrt(bs)*pow(r,2.0/3.0);
    return vc;
    }
    Are you sure? This action cannot be undone.
    Cancel
  • PuneetVerma

    MemberAug 26, 2014

    #include<iostream>
    #include<cmath>
    using namespace std;
    float vel(float,float,float);
    int main()
    {
    float p,qc,qr,d,w,ac,h,hg,v,b=1.5,dl=8,ss1=1.0,ss2,bs,wpr;
    int x,y,z;

    cout<<"For Lined Channe.. Press 1\nFor Unlined Channel.. Press 2\n"<<endl;
    cin>>x;
    cout<<"For Cutting Section.. Press 3\nFor Filling Section.. Press 4\n"<<endl;
    cin>>y;
    cout<<"For Power channel.. Press 5 \nFor Head Race Channel.. Press 6"<<endl;
    cin>>z;
    if(x==1&&y==3)
    {ss2=1;
    }
    else if(x==1&&y==4)
    {ss2=1.5;
    }
    else if(x==2&&x==3)
    {ss2=1.5;
    }
    else
    {
    ss2=2;}
    if(z==5)
    {bs=1.0/200.0;
    }
    else
    {bs=1.0/500.0;
    }
    cout<<"Enter Power Potential in MW = ";
    cin>>p;
    cout <<"Enter Gross Head in meters = ";
    cin>>hg;
    h=(0.9*hg);
    qr=(p*1000)/(9.81*0.8*h);
    qc=0.0;
    d=0.0;
    while(qc<qr)
    {d=d+0.05;
    w=d;
    if(d<=4.0)
    {ac=w*d;
    wpr=w+(2*d);}
    else if(d<=8.0)
    {ac=(w+ss1*d)*d;
    wpr=w+(2*pow(1.0+pow(ss1,2.0),0.5)*d);}
    else
    {ac=((w+ss1*dl)*dl)+((w+2*ss1*dl+2*b)+ss2*(d-dl))*(d-dl);
    wpr=w+(2*pow(1.0+pow(ss1,2.0),0.5)*dl)+(2*b)+(d-dl)*pow(1+pow(ss2,2.0),0.5);
    }
    v= vel(ac,bs,wpr);
    qc=ac*v; }
    if(d<=4.0)
    {cout<<"Channel Section is Rectangular\n";}
    else if(d<=8.0)
    {cout<<"Channel Section is trapezoidal\n";}
    else
    {cout<<"Channel is composite\n";}
    cout<<"Value of Diameter in metre = "<<d<<"\n";
    cout<<"Value of Width in metre = "<<w<<"\n";
    cout<<"Value of Discharge = "<<qc<<"\n";
    }
    float vel(float a,float bs,float pe)
    {
    float n,r,v;
    n=0.018;
    r=a/pe;
    v=(pow(r,2.0/3.0)*pow(bs,1.0/2.0))/n;
    return v;
    }


    I tried to do some changes and it is working now. Don't find exact difference.
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberAug 27, 2014

    Look at the code snippet below.
      if (z=4)
         {
    cout<<"Power Channel\n";
         
    bs=(1/200);
         }
    if (z=4) will always be true as assignment operator is used.
    I have not run your code through compiler, but this was surely one of the mistakes in your code, there may be more.
    Are you sure? This action cannot be undone.
    Cancel
  • Dennis Ighowho

    MemberSep 3, 2014

    please what is this program suppose to do? i mean the output?
    Are you sure? This action cannot be undone.
    Cancel