### Code not working properly, condition is being ignored, no errors.

No matter how hard I try, I can not find anything wrong with this code, lol.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` `````` #include #include #include using namespace std; void skaitymas (); void poru_skaiciavimas (); void atliekamos (); int i, z, q, c, n, vyr=0, mot=0, amot=0, avyr=0, lyt[100],rank[100], dyd[100]; int main(){ skaitymas (); poru_skaiciavimas (); atliekamos (); } void skaitymas () { ifstream in ("a.txt"); in >> n; for(i=0; i> lyt[i] >> rank[i] >> dyd[i]; // cout << lyt[i] << " " <

Last edited on
Are the conditions on line 45 met correctly? if they aren't the code will ignore everything that is between the { } on that if statement.
put a breakpoint on line 30 and tell us what your value for n is?
I figured out `dyd[z]==dyd[q]` needs to be `dyd[z]=dyd[q]` as with those 2 conditions code works normally, but the problem remains with `rank[z]==rank[q]+1 || rank[z]+1==rank[q]`, it just doesn't want to do what I want and if I try to delete one equal sign, it gives me
 lvalue required as left operand of assignment

So the question emerges, what's the actual difference between dyd[z] = / == dyd[q] ? I thought == means "is equal to" while = is supposed to mean simply "is" when declaring values, isn't it?... and how the heck do i tell it to simply check if one array is equal to other array+1?

 put a breakpoint on line 30 and tell us what your value for n is?

Here is the txt:
 ``123456789101112131415`` ``````14 4 1 25 4 1 13 4 2 15 4 2 25 3 2 42 3 2 25 4 1 25 3 1 25 4 1 25 3 1 42 3 1 25 3 1 36 4 1 24 4 1 15``````

as we can see, 7 and 9 lines lyt[z]=lyt[q]=3, dyd[z]=dyd[q]=25, rank[z]+1=rank[q] (rank[z]=1; rank[q]=2)

so theoretically, conditions are met at least once.

Last edited on
The code as posted in the original post works fine for me with the dataset you posted.

 I figured out dyd[z]==dyd[q] needs to be dyd[z]=dyd[q] as with those 2 conditions code works normally

Doubtful. Setting dyd[z] to the value held by dyd[q] means that portion of the condition will always be true except when dyd[q] happens to be 0 (which in this case would be never.) You would also be changing the same element multiple times in the loop, which doesn't seem very useful.
Topic archived. No new replies allowed.