Is there anything obviously wrong... 
Author Message
 Is there anything obviously wrong...

with these switch statements?  It looks like it should work, but it seems
like the case -1 of the dir switch never gets executed, even though dir
switches back and forth from -1 to 1 regularly.

In a nutshell, here's what I want from this segment:  If dir = 0, do
nothing.  If dir = 1, set status = 1 unless it already is.  If dir = -1, set
status = -1 unless it already is.  My tests show that status never gets
changed from 1 no matter how many times dir is changed back and forth.  I
suspect I'm messing up with my syntax here.

Also, note that I ended every case statement with a break;  - I get errors
if I leave any case statements without statements in them (?) so even the
ones that should do nothing had to have something in them.  VC++6

Thanx.

Brian-

switch (dir){
    case 0 : //no slope - unused portion of array
        break;
    case -1 : //current slope is negative
        switch (status){
            case 0 : // currently not in the market
                // enter market short
                inprice = *(PriceArray + count);
                status = -1;
                break;
            case -1 : // currently in short
                // hold short position
                break;
            case 1 : // currently in long
                // reverse to short
                balance += *(PriceArray + count) - inprice;
                inprice = *(PriceArray + count);
                status = -1;
                break;
        }
    case 1 : //current slope is positive
        switch (status){
            case 0 : // currently not in the market
                // enter market long
                inprice = *(PriceArray + count);
                status = 1;
                break;
            case -1 : // currently in short
                // reverse to long
                balance += inprice - *(PriceArray + count);
                inprice = *(PriceArray + count);
                status = 1;
                break;
            case 1 : // currently in long
                // hold long position
                break;
        }

Quote:
}



Tue, 20 Apr 2004 04:30:32 GMT  
 Is there anything obviously wrong...

See notes below:


Quote:
> with these switch statements?  It looks like it should work, but it seems
> like the case -1 of the dir switch never gets executed, even though dir
> switches back and forth from -1 to 1 regularly.

> In a nutshell, here's what I want from this segment:  If dir = 0, do
> nothing.  If dir = 1, set status = 1 unless it already is.  If dir = -1,
set
> status = -1 unless it already is.  My tests show that status never gets
> changed from 1 no matter how many times dir is changed back and forth.  I
> suspect I'm messing up with my syntax here.

> Also, note that I ended every case statement with a break;  - I get errors
> if I leave any case statements without statements in them (?) so even the
> ones that should do nothing had to have something in them.  VC++6

> Thanx.

> Brian-

> switch (dir){
>     case 0 : //no slope - unused portion of array
>         break;
>     case -1 : //current slope is negative
>         switch (status){
>             case 0 : // currently not in the market
>                 // enter market short
>                 inprice = *(PriceArray + count);
>                 status = -1;
>                 break;
>             case -1 : // currently in short
>                 // hold short position
>                 break;
>             case 1 : // currently in long
>                 // reverse to short
>                 balance += *(PriceArray + count) - inprice;
>                 inprice = *(PriceArray + count);
>                 status = -1;
>                 break;
>         }

           break;            // don't fall through to 1.

- Show quoted text -

Quote:
>     case 1 : //current slope is positive
>         switch (status){
>             case 0 : // currently not in the market
>                 // enter market long
>                 inprice = *(PriceArray + count);
>                 status = 1;
>                 break;
>             case -1 : // currently in short
>                 // reverse to long
>                 balance += inprice - *(PriceArray + count);
>                 inprice = *(PriceArray + count);
>                 status = 1;
>                 break;
>             case 1 : // currently in long
>                 // hold long position
>                 break;
>         }

           break;                // not really needed, but why not

Quote:
> }

--
Jay


Tue, 20 Apr 2004 04:36:23 GMT  
 Is there anything obviously wrong...
Looks to me that you are missing a break at the end of the case -1 for the
dir switch.


Quote:
> with these switch statements?  It looks like it should work, but it seems
> like the case -1 of the dir switch never gets executed, even though dir
> switches back and forth from -1 to 1 regularly.

> In a nutshell, here's what I want from this segment:  If dir = 0, do
> nothing.  If dir = 1, set status = 1 unless it already is.  If dir = -1,
set
> status = -1 unless it already is.  My tests show that status never gets
> changed from 1 no matter how many times dir is changed back and forth.  I
> suspect I'm messing up with my syntax here.

> Also, note that I ended every case statement with a break;  - I get errors
> if I leave any case statements without statements in them (?) so even the
> ones that should do nothing had to have something in them.  VC++6

> Thanx.

> Brian-

> switch (dir){
>     case 0 : //no slope - unused portion of array
>         break;
>     case -1 : //current slope is negative
>         switch (status){
>             case 0 : // currently not in the market
>                 // enter market short
>                 inprice = *(PriceArray + count);
>                 status = -1;
>                 break;
>             case -1 : // currently in short
>                 // hold short position
>                 break;
>             case 1 : // currently in long
>                 // reverse to short
>                 balance += *(PriceArray + count) - inprice;
>                 inprice = *(PriceArray + count);
>                 status = -1;
>                 break;
>         }
>     case 1 : //current slope is positive
>         switch (status){
>             case 0 : // currently not in the market
>                 // enter market long
>                 inprice = *(PriceArray + count);
>                 status = 1;
>                 break;
>             case -1 : // currently in short
>                 // reverse to long
>                 balance += inprice - *(PriceArray + count);
>                 inprice = *(PriceArray + count);
>                 status = 1;
>                 break;
>             case 1 : // currently in long
>                 // hold long position
>                 break;
>         }
> }



Tue, 20 Apr 2004 04:34:42 GMT  
 Is there anything obviously wrong...
Thanks, you guys.. I knew it was something simple.

Brian-


Quote:

> See notes below:



> > with these switch statements?  It looks like it should work, but it
seems
> > like the case -1 of the dir switch never gets executed, even though dir
> > switches back and forth from -1 to 1 regularly.

> > In a nutshell, here's what I want from this segment:  If dir = 0, do
> > nothing.  If dir = 1, set status = 1 unless it already is.  If dir = -1,
> set
> > status = -1 unless it already is.  My tests show that status never gets
> > changed from 1 no matter how many times dir is changed back and forth.
I
> > suspect I'm messing up with my syntax here.

> > Also, note that I ended every case statement with a break;  - I get
errors
> > if I leave any case statements without statements in them (?) so even
the
> > ones that should do nothing had to have something in them.  VC++6

> > Thanx.

> > Brian-

> > switch (dir){
> >     case 0 : //no slope - unused portion of array
> >         break;
> >     case -1 : //current slope is negative
> >         switch (status){
> >             case 0 : // currently not in the market
> >                 // enter market short
> >                 inprice = *(PriceArray + count);
> >                 status = -1;
> >                 break;
> >             case -1 : // currently in short
> >                 // hold short position
> >                 break;
> >             case 1 : // currently in long
> >                 // reverse to short
> >                 balance += *(PriceArray + count) - inprice;
> >                 inprice = *(PriceArray + count);
> >                 status = -1;
> >                 break;
> >         }
>            break;            // don't fall through to 1.
> >     case 1 : //current slope is positive
> >         switch (status){
> >             case 0 : // currently not in the market
> >                 // enter market long
> >                 inprice = *(PriceArray + count);
> >                 status = 1;
> >                 break;
> >             case -1 : // currently in short
> >                 // reverse to long
> >                 balance += inprice - *(PriceArray + count);
> >                 inprice = *(PriceArray + count);
> >                 status = 1;
> >                 break;
> >             case 1 : // currently in long
> >                 // hold long position
> >                 break;
> >         }
>            break;                // not really needed, but why not
> > }

> --
> Jay



Tue, 20 Apr 2004 04:52:10 GMT  
 Is there anything obviously wrong...

Quote:

> with these switch statements?  It looks like it should work, but it seems
> like the case -1 of the dir switch never gets executed, even though dir
> switches back and forth from -1 to 1 regularly.

You forgot the break after the code in case -1 in the outer [switch(dir)]
switch.

There for whenever dir is -1 it executes the inner switch then falls
through to the dir=1 case and does it's switch.



Tue, 20 Apr 2004 04:53:45 GMT  
 Is there anything obviously wrong...
Hello Brian,

Thank you for using Microsoft Visual C++ News Group.

After having a look of your code, I think the problem is that at least one
break statement was lost. The case statement functions as a label. The
process will go through the routine untill it encounters the break
statement. You have added the break statement to each case of the switch
(status), so it can work correctly. However you forget the break statements
of the case -1 and case 1 of switch (dir). Hence, when it completes the
case -1, it will go on to the case 1. The case -1 seems doesn?t work. This
is a sample code:

switch (dir)
{
        case 0 : //no slope - unused portion of array
                break;

        case -1 : //current slope is negative
                switch (status)
                {
                        case 0 : // currently not in the market
                                // enter market short
                                inprice = *(PriceArray + count);
                                status = -1;
                                break;
                        case -1 : // currently in short
                                // hold short position
                                break;
                        case 1 : // currently in long
                                // reverse to short
                                balance += *(PriceArray + count) - inprice;
                                inprice = *(PriceArray + count);
                                status = -1;
                                break;
                }
                break; //break for case -1

        case 1 : //current slope is positive
                switch (status)
                {
                        case 0 : // currently not in the market
                                // enter market long
                                inprice = *(PriceArray + count);
                                status = 1;
                                break;
                        case -1 : // currently in short
                                // reverse to long
                                balance += inprice - *(PriceArray + count);
                                inprice = *(PriceArray + count);
                                status = 1;
                                break;
                        case 1 : // currently in long
                                // hold long position
                                break;
                }
                break;  //break for case 1

Quote:
}

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

Quote:

>> Newsgroups: microsoft.public.vc.language
>> Subject: Is there anything obviously wrong...
>> Lines: 59
>> X-Priority: 3
>> X-MSMail-Priority: Normal
>> X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
>> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

>> Date: Thu, 1 Nov 2001 12:30:32 -0800
>> NNTP-Posting-Host: 206.190.87.51

>> X-Trace: newsfeed.avtel.net 1004646583 206.190.87.51 (Thu, 01 Nov 2001
12:29:43 PST)
>> NNTP-Posting-Date: Thu, 01 Nov 2001 12:29:43 PST
>> Organization: None
>> Path:

cppssbbsa01.microsoft.com!news-out.cwix.com!newsfeed.cwix.com!newsfeed.avtel
net!not-for-mail

- Show quoted text -

Quote:
>> Xref: cppssbbsa01.microsoft.com microsoft.public.vc.language:148427
>> X-Tomcat-NG: microsoft.public.vc.language

>> with these switch statements?  It looks like it should work, but it seems
>> like the case -1 of the dir switch never gets executed, even though dir
>> switches back and forth from -1 to 1 regularly.

>> In a nutshell, here's what I want from this segment:  If dir = 0, do
>> nothing.  If dir = 1, set status = 1 unless it already is.  If dir = -1,
set
>> status = -1 unless it already is.  My tests show that status never gets
>> changed from 1 no matter how many times dir is changed back and forth.  I
>> suspect I'm messing up with my syntax here.

>> Also, note that I ended every case statement with a break;  - I get
errors
>> if I leave any case statements without statements in them (?) so even the
>> ones that should do nothing had to have something in them.  VC++6

>> Thanx.

>> Brian-

>> switch (dir){
>>     case 0 : //no slope - unused portion of array
>>         break;
>>     case -1 : //current slope is negative
>>         switch (status){
>>             case 0 : // currently not in the market
>>                 // enter market short
>>                 inprice = *(PriceArray + count);
>>                 status = -1;
>>                 break;
>>             case -1 : // currently in short
>>                 // hold short position
>>                 break;
>>             case 1 : // currently in long
>>                 // reverse to short
>>                 balance += *(PriceArray + count) - inprice;
>>                 inprice = *(PriceArray + count);
>>                 status = -1;
>>                 break;
>>         }
>>     case 1 : //current slope is positive
>>         switch (status){
>>             case 0 : // currently not in the market
>>                 // enter market long
>>                 inprice = *(PriceArray + count);
>>                 status = 1;
>>                 break;
>>             case -1 : // currently in short
>>                 // reverse to long
>>                 balance += inprice - *(PriceArray + count);
>>                 inprice = *(PriceArray + count);
>>                 status = 1;
>>                 break;
>>             case 1 : // currently in long
>>                 // hold long position
>>                 break;
>>         }
>> }



Fri, 23 Apr 2004 11:02:32 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Am I wrong or the compiler is wrong?

2. Am I wrong or compiler is wrong?

3. Is there anything wrong with this ?

4. Is there anything wrong with this?

5. Is anything wrong with this declaration?

6. Can you see anything wrong with this code?

7. Anything wrong with this function?

8. Anything wrong with this calculation????

9. HELP: Anything Wrong With This?

10. Anything wrong with this code?

11. Is there anything wrong with this code?

12. anything wrong when using pop function?

 

 
Powered by phpBB® Forum Software