solution6 - CSCI-1100 Computer Science I Rensselaer...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/16/2008 for the course CSCI 1100 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Ask a homework question - tutors are online