Computer Science Canada Outputting average of all non-negative marks and invalid marks (IF STATEMENTS) |
Author: | Loomis [ Wed Nov 04, 2009 7:16 pm ] | ||||
Post subject: | Outputting average of all non-negative marks and invalid marks (IF STATEMENTS) | ||||
What is it you are trying to achieve? I am creating a program that continues to read marks from the user until a negative integer is inputted. For each non-negative mark entered, the program outputs the corresponding grade using a table. If a mark entered is greater than 100 the message "Invalid mark" is outputted. Also, the average of all the non-negative marks will be outputted. What is the problem you are having? I can't seem to output the average correctly because it gives this error " Division (or modulus) by zero in Real expression". Also, when I enter an invalid mark that is greater than 100, it still counts that. Describe what you have tried to solve this problem For the program not to count the invalid marks, I did this:
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) And this is the whole program:
Please specify what version of Turing you are using Turing Version 4.1.1 |
Author: | Tony [ Wed Nov 04, 2009 7:33 pm ] |
Post subject: | RE:Outputting average of all non-negative marks and invalid marks (IF STATEMENTS) |
When you get to the last line and try to use "sum/count" the value of count is 0. Hint: the value of "sum" is 0 as well. |
Author: | saltpro15 [ Thu Nov 05, 2009 8:04 am ] | ||
Post subject: | RE:Outputting average of all non-negative marks and invalid marks (IF STATEMENTS) | ||
That needs to be inside your loop, otherwise you're always adding a 0 to sum ![]() |