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:
- 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:
1 2 3
|
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.