CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 6 - Solutions 1. There is nothing wrong in the change program 2. The problem with the average program is that the variable sum is never initialized to 0 before beginning to compute the sum of the numbers. When using a variable to compute a sum, you must always initialize the variable to 0 first so that it has a valid value the first time that it is used. You should see this in the debugger the first time that variable sum in used in the statement " sum = sum + number; ". In the bottom left window of the debugger you will see a very large positive or negative number for variable sum . Such a number is always an indicator that a variable was not initialized before it was used. 3. The time program has several problems. First, the number of hours must be computed before the number of minutes so that the number of minutes includes only those seconds that are not part of the computed number of hours. You should observe this problem using the debugger when you first see
This is the end of the preview. Sign up
access the rest of the document.