### 4 Variable K-Map Simplifier Problem

I was doing this program to simplify the 4 variable K-Map.
The program works fine except for minterm combinations that contain the first minterm (in the code m[0]).
for those combinations it gives strange result that dont make sense to me. I cant find any logical problems in the code.
The program is pretty long (atleast by my standard).

1. Why cant i intialize the entire array, i.e. the last member cant be initialized?
2. I was told i should not use goto() but no reason was given, any simple explanation?
Thank you.

The code was too long to post so i am sharing a link. I hope its alright.

Here are a few ideas:

- Learn to use a debugger like gdb for example. This is by far the easiest way to find logical errors. There is a tutorial for it's use in the article section on this site.
- Can you make use of for loops to avoid lots of if statements?.
- make sure you initialise your variables - in this line b is not initialised:
 ``12`` ``````int b; for (b;b>=0;)``````

- have a think about what is happening with the above for loop;
 1. Why cant i intialize the entire array, i.e. the last member cant be initialized?

Arrays subscripts start at zero, so M[31] is past the end of the array. To loop through this array & initialise them all to 0, do this:

 ``123`` ``````for(int a = 0; a < 31; ++a) { M[a] = 0; }``````

This may be why you have problems with m[0].

 2. I was told i should not use goto() but no reason was given, any simple explanation?

There are some cases where the use of goto is OK, but only if you know what you are doing. In general they should be avoided, because they lead to very bad code. Make use of a proper loop structure like while or for instead.

I had a quick read of the wiki page about this topic - are you sure you are using the right algorithm? It's just that the K- Map is supposed to make things easier, but you have a lot of complex logic. I may completely wrong with that last statement - treat it as a random thought.

Hope all goes well.
Thanks for the response.

- I will do that.
- Cant make a loop as far as i can think. There is no set pattern or at least no simple enough pattern.
- got it about array initialization, thanks.
- goto isn't the problem in this case.

So all in all you did give some good advice and thanks for that, but my problem is still there and i don't have time to learn that debugger right now. :(