I could use a bit of help with an assignment for class.
3 04 Feb 2018 05:05 by u/Firevine
This is going to be pathetically easy for you guys, but I am super, super new to this, and this textbook is a pile of hot garbage.
I get that there's currently no way to input test3, but I'm not sure how to add that simply. We can't rewrite the whole shebang, rather we have to work within the confines of how it's already written, making as few changes as possible. I'm thinking I just need to add the following two lines to the mainloop module
output "Enter score for test 3"
input test3
The (very) brief rundown on Modularization describes the benefits which I get, and the syntax, buuuuuuuut that's about it.
Thanks in advance.
10 comments
2 u/webslingr 04 Feb 2018 12:09
Step 1, I would enter a second line in housekeeping():
Step 2, I would enter two lines in mainLoop() after "input test2":
Done.
0 u/Firevine [OP] 04 Feb 2018 20:48
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.
0 u/enginedriver13 04 Feb 2018 05:36
Seems right to me?
0 u/AmaleksHairyAss 04 Feb 2018 05:52
The first problem I see is that 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.
0 u/Glory_Beckons 04 Feb 2018 07:06
If we were to unroll the logic, here is what you want the program to do:
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).
0 u/Glory_Beckons 04 Feb 2018 07:36
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:
This is a bit different. Ignore 2, 4, 5 above. 1 and 3 still apply.
Have you covered break/continue? Or "do while" loops as opposed to while loops?
0 u/Firevine [OP] 04 Feb 2018 08:13
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.
0 u/Glory_Beckons 04 Feb 2018 16:44
It's tough for everyone, as you can see by my initial mistake. It's often down to a keyword or two. That's the trouble with examples like this. They tend to be odd and intuitive, and have multiple solutions even though the authors want only a very specific one. It's just how it is.
If you're just starting, you probably won't be dealing with GUI applications any time soon.
How would you implement an exit command? Type in "exit" instead of a test score?
The test scores are declared as numbers. They won't accept "exit" as an input. Once you encounter an "input testx", the user must input a number to continue. -1 can never be a valid test score, so it's a convenient "get me out of here". You'll encounter -1 being used to indicate "not valid", "error", "exit" all over the place. It's a very common convention.
You could have an additional "Do you want to continue (yes/no):" input as part of the loop. But that would involve more code that has nothing to do with what this example is about and get annoying if you want to input 30 test scores.
0 u/Firevine [OP] 04 Feb 2018 20:54
Might be part of my confusion! I keep visualizing these as very basic Win98 looking GUI programs as I go through the steps. Also the last time I coded anything at all was farting around with HTML on an Angelfire site...
0 u/vantile95 04 Feb 2018 13:17
I like that. It really like I like kiểm tra số điện thoại viettel