Assignment one questions and answers

Here are some questions and answers about assignment one. Suggestions for additions to this list are welcome (via e-mail).


Q: I uploaded my file at 11:45 last night [October 4th] and it didn't work at ECF, but it worked fine at home. May I have an extension on account of this?

A: No. It's simply not possible for us to accommodate problems with your own equipment. Officially, I suggest you use the ECF computers, which are professionally managed, and which have installed a good C compiler which correctly implements the C programming language. Use of your own equipment is at your own risk; I can sometimes assist you with it, and I'm not opposed to it, but if problems with your own computer were allowed to cause you to have extensions, everyone would have free extensions. It's just not feasible.

At this date [October 5th] it's a bit late for this information to be of use to you for assignment one. Fortunately I have a time-warp here so I'll post this on the CSC 180 web pages retroactively on September 27th. Please be advised.


Q: If the day number is 1, should my program print "1th" or "1st"?

A: It is ok to print "1th". To do otherwise complicates your program and is not a requirement of the assignment.


Q: May my program print "1st", "2nd", etc, instead of "1th"?

A: Yes it may, but I suggest that you focus on implementing the required specification instead of extra features. If your extra features cause your program to malfunction, you will lose marks. Similarly, in the "real world" it is better to implement an impoverished set of features correctly than to implement an all-singing all-dancing system which is full of bugs. There is an oft-cited acronym "KISS" which stands for "keep it simple, stupid".


Q: If the user types letters instead of an integer for the input, should my program loop and prompt them to retry?

A: No. The assignment handout says that your program should "not proceed". Perhaps this wasn't the best wording for me to use. Your program should display "Bad input" and exit (i.e. return from main()).

Loops are not needed for assignment one until you get to firstmonday.c.


Q: Can I assume that your testing procedure will supply correct input to my program?

A: No. You have to provide the "Bad input" or "Invalid date" error messages.


Q: Exactly what input format checking do I have to perform?

A: As the assignment handout says, just check whether scanf("%d%d%d", ...) returns 3. That's about the limit of how nicely you can handle numeric input with scanf anyway. We'll do input better later in the course. I'm currently planning an exploration of more "user-friendly" input for lab 8.


Q: My program checks whether the day number is greater than 31, which is what the assignment handout says to do, so it accepts dates such as February 30th and April 31st. Is this ok?

A: Yes, that is ok. The only date-calculating code your assignment one program is required to perform is the day-of-the-week calculation.


Q: I tried to loop in the case of bad input and prompt again. My program works fine if numbers are inputted but if you type something else, like letters, it just prints the prompt over and over.

A: This is because scanf() does not read the letters, so they're still there, pending, and so the next scanf() call fails too, and so on, forever. It never gets past the letters. This is the main reason I said your program should simply exit when there is bad input (e.g. return from main()), rather than looping and re-prompting. As I say, we'll do better than this in approximately lab 8.


Q: Do we have to deal with the case where the user inputs more than or fewer than three integers?

A: Your program should not malfunction in any case.

If scanf() returns a number other than 3, you should say "Bad input", whatever the cause.

If the user types more than three integers, scanf will still return 3, and you should proceed without noticing the error.

If the user types two integers, scanf("%d%d%d", ...) will still be waiting for input. No error has occurred yet. If the user turns off the computer before typing a third integer, then that is an error, but your program is no longer in a position to do anything about it. If instead of turning off the computer they proceed to type "help, let me out of here!" then scanf() will return 2 and your program should say "Bad input" and exit.

The main point is that if scanf() returns three then it has put some value into the three int variables you pass it, so nothing too bad will happen. If it returns a number other than three, it has not filled in values for all the variables, so you should not proceed to use them.


[main course page]