Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this error in a code I am writing to use method to carry out a formula with an initial value
like
C#
public static double miuk;
        public static double yp = 0;
        private static double e_e = Exp(ref time,out Yt(out yp));//error
        private static double N1, N2, N3, N4, C1, C2, C3, C4;
        private static double Exp1 = Summation(ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4);

        public static double SN(ref double miuK,out double yp )
        {
            yp = 0;
            //yp = Yt(ref miuK,out yp);
            return Xp*B*P*((miuK*(1-Math.Exp(-(e_e)))-1)+(yp*Math.Exp(-(e_e))*Exp1));
            
        }

        public static double Yt(out double yp)
        {
            yp = 0;
            return Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (yp*(Math.Exp(-(e_e))));
        }




How do I give the new value gotten from the return to "yo" all over again

Any one with useful idea please its urget.
Posted
Updated 5-Dec-14 14:41pm
v2
Comments
Matt T Heffron 5-Dec-14 20:34pm    
This can't be the only error message you're getting as this code is broken in several ways. Show us the real code, in context, and where it is called, and where the error is reported!. Then we can give reasonable advice.
(P.S., it isn't "urgent" to us...)
Oluwasetemi! 5-Dec-14 20:47pm    
I have adjusted the question

1 solution

C#
private static double e_e = Exp(ref time,out Yt(out yp));//error

You cannot pass the Yt(out yp) call as an out parameter.

An out parameter must be to a variable or field. It must be a writable location.

I don't know how your Exp(..., ...) method is defined.

(Having a name that similar to Math.Exp() is not a good idea, especially since you also are using Math.Exp() in this code!)

Show the Exp(..., ...) method and I can probably help...
It looks like you really don't need so many out parameters all over the place.

[Edit: MTH]
I'm not sure about this since I still cannot tell what you're actually trying to do.
If you want Yt to always operate on the static yp value, and always to update it then maybe something like:
C#
public static double Yt()
{
    yp = Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (yp*(Math.Exp(-(e_e))));
    return yp;
}

Otherwise, maybe more like:
C#
public static double miuk;
public static double yp = Yt(0);
private static double e_e = Exp(time, yp);
private static double N1, N2, N3, N4, C1, C2, C3, C4;
private static double Exp1 = Summation(ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4);
 
public static double SN(ref double miuK,out double yp)
{
// fixing this one left as an exercise... ;-)
    yp = 0;
    //yp = Yt(ref miuK,out yp);
    return Xp*B*P*((miuK*(1-Math.Exp(-(e_e)))-1)+(yp*Math.Exp(-(e_e))*Exp1));
}
 
public static double Yt(double ypParam)
{
    return Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (ypParam*(Math.Exp(-(e_e))));
}

public static double Exp(double rtime, double ypParam)
{
  return Math.Exp(-(Q*F - Yt(ypParam))*Lamda)*rtime;
  // did you really intend to apply Yt to the ypParam here since the ypParam IS itself Yt(yp)?
  // I.e., this is Yt(Yt(yp))
}


As a general rule, lots of use of out (and/or ref) parameters, and lots of static fields (variables) is a sign that the code was not thought out before implementing! (a.k.a., "code smell")
 
Share this answer
 
v2
Comments
Oluwasetemi! 5-Dec-14 20:59pm    
public static double Exp(ref double rtime,out double yp)
{
return Math.Exp(-(Q*F - Yt(out yp))*Lamda)*rtime;

}
Matt T Heffron 5-Dec-14 21:02pm    
There's no reason for rtime to be ref, it is never modified.
yp probably doesn't need to be out, either.
Give me a couple of minutes to update my Solution above...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900