Hey guys, any idea as to how to find the lowest value and the highest value in this 2D array? I made the functions to find the lowest and highest, but all im getting on execution is a 1 on both, no matter what number i input.
This is what im having problems with, when i apply the lowest = table[monkey][day]; to my code, it doesn't work for finding the lowest, but it works for finding the highest. Heres my complete code, the problem is that it is still not finding the lowest:
Also, now that this is working, how could i write all this information to a file? could it be done with one function? or would it have to be implemented on every function i do?
coz if it's initialize to 0 at line 97, any value would be greater. thus the program proceeds correctly.
u can try this: does not change ur original line 81, but put a -1 in the table. this time the return for findlowest is -1. same if u put all negative to the table, the return for findHighest would be 0.
this gives u an insight of how arrays are initialized.
keep close to declarations. as input are set to be table [][DAYS], from line 10 to 14, the newer compilers will recognize it as a dynamic array. even it's not allowed initially for C++, certain compilers will "reserve" spaces for upcoming rows at table[MONKEYS]. and initialization for these reserves are 0. i'm not saying this is true in all case, but is possible in a lot cases.
also, line 81 does not have to initialize as this. using a member within the data structure, which is likely in register, is faster than call INT_MAX, which is definitely not in register.
I was actually thinking this: before the function call jump to designated mem location for findHighest and findLowest, which data IS in mem cache at that moment. INT_MAX is not, so the system would go and grab it. but in this case, as after assigning the last data in table, that is table[MONKEYS-1][DAYS-1], it is not likely have been replaced and erased from the cache yet. Thus, as a cache hit is faster than a cache miss which INT_MAX results, it should be faster to assign table[MONKEYS-1][DAYS-1].
If you have any information proving above is not true, please let me know. I'd like some reference as well. I always believe the above is right, so it would be good to know if I got it wrong. With certain proof of course.
Also, this may be a little out of the topic. So if you'd like continue this discussing elsewhere like PM or through e-mail, you are certainly welcome.
If you are allowed to use standard C++ algorithm classes, you can amend your 2D array a bit (as in make it like one long list of elements) to call below functions.