This week's book giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line! See this thread for details.
John Matthews wrote:Hi Eve - please could you post the rest of the code as well so I can compile it?
Sure, John! I have tried sending the complete code, but received a "Post is too long, please shorten it. Alternatively you can buy some Pie from an upper menu to increase a post limit by 10000 characters per pie slice," warning. So I have posted my code to this link https://paste.ubuntu.com/p/7ZVmwnsX22/ feel free to check it out!
Thanks. I just added a printf() in the code where the average score is calculated and played one round - the printf() showed the average being updated correctly.
Then I was about to play my 2nd round - entered 'P' - and the printf() output again; my first round score had been added to allScore again, so it was no longer correct.
Try adding some printfs yourself - it's a simple way to debug code, doesn't need a fancy debugger.
...and the output shown in your original post confirms my printfs.
The output shows an (incorrect) average of 127. Well it looks like your first round score was 84, and second round was 87. (84 + 84 + 87) = 255, and (255 / 2) = 127.
John Matthews wrote:Thanks. I just added a printf() in the code where the average score is calculated and played one round - the printf() showed the average being updated correctly.
Then I was about to play my 2nd round - entered 'P' - and the printf() output again; my first round score had been added to allScore again, so it was no longer correct.
Try adding some printfs yourself - it's a simple way to debug code, doesn't need a fancy debugger.
Thank you, may I ask which line of the code are you referring to?
Suggestions for improving/correcting print_positive_message():
(correction) The function argument should be void; if left empty it means unspecified (although it would be correct in C++).
The function should be static - it is only used in this file.
The words array should be static, otherwise it is created on the stack every time the function executes.
The word array should be a (const) one dimensional array of (const) char pointers, not a 2 dimensional array of char. The compiler will store the strings in memory for you, only using as much memory as it needs to.
Use the ARRAY_SZ() macro to give the size of the array for the modulo calculation; avoids the use of 'magic numbers' and reduces maintenance overhead.
Move the '\n' and '!' into the printf() format string because they are common to all strings.
Don't get me started about those stupid light bulbs.