CISC 105 Lab 04 FAQ
For each of the following questions, I'll give suggestions for
"troubleshooting" the problem.
Notes from Sara:
- NEW: I will be looking more closely at your comments and
good variable naming, so make sure you name variables appropriately.
- When you script your answers, run each program a couple times with
different values, when appropriate. For example, for the printing
red/blue problem, you should execute the program at least once to
print red and at least once to print blue. (Bonus: think about what
the "best" numbers to prove that your code is correct.)
- Running the program multiple times with different input is also
useful to you in testing that your program works appropriately.
- We are requiring good testing, e.g., running the
program with multiple, "interesting" input values, in all future
assignments, including project 1. For example, would entering a
negative number break your program for the red/blue printing program?
We will talk more about "interesting" input values in future labs.
- If your comments are not broken into several lines, they may be
cutoff in the printout. One solution is to type
esc q
on
a long line. The shortcut esc q
breaks the comments so
that they're less than the width of the page.
Can we use breaks?
The only time you can use breaks is in switch statements. You
CANNOT use breaks in while loops.
Is it okay if we have an extra space at the beginning of the
square of asterisks?
Yes, that's okay.
For number 6, is this "void" function the same that we have been
using, a.k.a. int main () { }?
No, main is an "int" function. You want to create a function that is
of type "void", i.e., it does not return anything.
I don't want to say too much, and I probably have already confused
you. You may want to wait until after Wednesday's class to do this
problem because Terry will cover void functions then.
Problem 7
Several people have asked me about the factorial problem and their
trouble with computing the factorial of large numbers. (Do you know
what problem they are running into?) The definition of "large"
numbers changes if the result is stored in an int, float, or double.
My recommendation: It is reasonable for you to put some restrictions
on the input--like that you'll compute factorial for positive integers
less than x. But what is the value of x? And, how will you prevent your
program from computing the factorial of numbers greater than x?