Cout getting ignored

My cout is getting ignored.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

using namespace std;

int main()
{
    while(true){
        int bugs,order;
        cout<<endl<<"how many bugs?"<<endl;
        cin>>bugs;
        if(bugs==3){
            cout<<"order?"<<endl;cin>>order;
            if(order==213){cout<<"bad!\a";}else{cout<<"good!\a";}
        }
        else if(bugs==4){
            cout<<"order?"<<endl;cin>>order;
            if((order==1324)||(order==2134)||(order==2314)||(order==3214)||(order==3124)||(order==2143)||(order==3241)||(order==3142)||(order==2413)){cout<<"bad!\a";}else{cout<<"good!\a";}
        }
        else if(bugs==5){
            cout<<"order?"<<endl;cin>>order;
            if((order==12435)||(order==13245)||(order==13254)||(order==13425)||(order==13524)||(order==14325)||(order==14352)||(order==14235)||(order==14253)||(order==15324)||(order==21354)||(order==21435)||(order==21453)||(order==21534)||(order==21543)||(order==23145)||(order==23154)||(order==23415)||(order==23514)||(order==24315)||(order==24351)||(order==24135)||(order==24153)||(order==24513)||(order==25314)||(order==25413)||(order==25134)||(order==25143)||(order==32145)||(order==32154)||(order==32415)||(order==32451)||(order==32514)||(order==32541)||(order==31245)||(order==31254)||(order==31425)||(order==31452)||(order==31524)||(order==31542)||(order==34125)||(order==34152)||(order==34215)||(order==34251)||(order==35142)||(order==35124)||(order==35214)||(order==35241)||(order==42315)||(order==42351)||(order==42135)||(order==42153)||(order==42531)||(order==42513)||(order==43215)||(order==43251)||(order==43125)||(order==43152)||(order==43521)||(order==43512)||(order==41325)||(order==41352)||(order==41235)||(order==41253)||(order==41532)||(order==41523)||(order==45213)||(order==52314)||(order==52413)||(order==52134)||(order==52143)||(order==53241)||(order==53214)||(order==53124)||(order==53142)||(order==51324)){cout<<"bad!\a";}else{cout<<"good!\a";}
        }
    }
    return 0;
}

If I type 5 bugs, order 12345, the cout doesn't run. It's supposed to say
good
.
Hello!

I just tested your program. It works just fine on my side!

Edit: what version of Visual Studio are you running? 2013 or 2010? I've run into some issues compiling with 2010 myself. If you're using 2010 you might want to go into project >> properties >> linker >> set incremental linking to NO
Last edited on
I'm using CodeBlocks 13.12.
One big issue I see is that there is to much on single lines. This makes finding the problem a pain.
It is good practice to keep each statement on its own line. That way, if the compiler flags an error on a certain line, you wont have to search for the problem. It will also be a lot easier to to read.
Also, with a little boolean algebra, the if statements can be reduced greatly.
The if statement for the order of 5 bugs can be rewritten by swapping the else and the if. The code will be a lot cleaner and easier to debug if your if statement takes the smallest path:

1
2
3
4
5
6
7
8
if((order == 12345) || (order == any_other_correct_combo))
{
    cout << "good!\n";
}
else
{
     cout << "bad!\n";
}


Sorry if this isn't much help but it is nearly impossible to locate the problem when your code is formatted the way it is.
Could there be a "compiler-hardcoded" limit to the number of boolean operators in one if statement? I think I remember reading about something like that, though I could be wrong. Perhaps it's 127, although it seems the original post only has 73 || operators.
Last edited on
what OS and compiler are you using with Code::Blocks?
Don't forget to flush.

cout << "good\a" << flush;

Hope this helps.
Topic archived. No new replies allowed.