[–] AmaleksHairyAss 0 points 3 points (+3|-0) ago  (edited ago)

It tests an undefined number for a value. test1 is declared, not given a value, and then a while loop is run based on its value.

If the value of test1 is assumed to be zero after it is declared the program will output

Enter score for test 1
Enter score for test 2

Furthermore that null or zero value will be fed into the equation for the average. So will an initial null or zero value for test3.

To fix this requires multiple lines in multiple places. I would fix the above and then worry about how to allow input for test3.

[–] webslingr 0 points 2 points (+2|-0) ago  (edited ago)

Step 1, I would enter a second line in housekeeping():

    input test1

Step 2, I would enter two lines in mainLoop() after "input test2":

    output "Enter score for test 3"
    input test3

Done.

[–] Firevine [S] 0 points 0 points (+0|-0) ago 

Oh hey cool, I had it half right then. I did step 2 last night before seeing your response, but I did not do step 1. Thanks a ton! It's clicking a bit now (I was stressing out last night). I'm trying so hard to maintain this GPA that I think I'm psyching myself out on things.

[–] Glory_Beckons 1 points 0 points (+1|-1) ago  (edited ago)

EDIT: This isn't right, see reply. Leaving it since it still might be informative, just not what they were after.

If we were to unroll the logic, here is what you want the program to do:

output "Enter score for test 1 or negative number to quit"
input test1
if test1 < 0: goto end

output "Enter score for test 2 or negative number to quit"
input test2
if test2 < 0: goto end

output "Enter score for test 3 or negative number to quit"
input test3
if test3 < 0: goto end

average = (test1 + test2 + test3) / 3
output "Average is ", average

end:
output "End of program"

Obviously there is much repetition here, not to mention the goto's, which is why we want to structure it better. But this is what you want your program to achieve, and (usually mentally) laying it out in a linear fashion like this is very useful for debugging (make a habit of it).

  1. Is this what your program does? Go through line by line and look for discrepancies. (Pretend you're the computer, executing each line as you go. Use some scratch paper to write down each line that would be output if it helps)
  2. Obviously the repeated blocks should be looped, the goto condition becoming the loop condition. Compare to your current loop condition.
  3. Note that the loop condition cannot be checked before the corresponding input, it has to be after.
  4. Note we have to skip the average calculation and output if we aborted.
  5. Have you covered arrays/lists? That would help here considerably.

[–] Glory_Beckons 0 points 1 points (+1|-0) ago 

Actually, scratch that... I should have paid more attention to the comment at the top. ("for any number of students ... until user enters negative value for first test score")

This is what they want it to do:


start:

output "Enter score for test 1 or negative number to quit"
input test1

if test1 < 0: goto end

output "Enter score for test 2"
input test2
output "Enter score for test 3"
input test3
average = (test1 + test2 + test3) / 3
output "Average is ", average

goto start

end:
output "End of program"

This is a bit different. Ignore 2, 4, 5 above. 1 and 3 still apply.

  1. The input of test1 is what they called "housekeeping". Except where is the input?
  2. End is still fine
  3. The big block is what they called mainloop (I wouldn't worry about the repetition, and I assume you haven't covered arrays yet)
  4. The tricky bit is the loop condition. You need "housekeeping" inside the loop, but you cannot check test1 until after it has run.

Have you covered break/continue? Or "do while" loops as opposed to while loops?

[–] Firevine [S] 0 points 0 points (+0|-0) ago 

Have you covered break/continue? Or "do while" loops as opposed to while loops?

Not yet. We're only into the second chapter of the textbook. It's just...not a great textbook... I sent a shot of one of the pages to my friend and he was confused as to why they were even going on about some of the things they were.

I find it difficult to get into someone else's head quite often, so following the logic of why the writers wrote this the way they did is tough for me. It's kind of unintuitive. Why a negative value to exit rather than an exit button, or even an exit command if this were a command line program? Weird. That's not the scope of the assignment though, so I shouldn't dwell on it, lol.

I appreciate the assistance. Looks like I was on the right track, but I mainly wasn't sure if I had to write an additional module for test 3.

[–] vantile95 2 points -2 points (+0|-2) ago 

I like that. It really like I like kiểm tra số điện thoại viettel