What is the error in the following code if its purpose is to add five numbers entered by the user?
int x, sum;
for ( int c = 0; c < 5; c++)
{
cout << “Next number\n”;
cin >> x;
sum = sum + x;
}
sum is not initialized to zero.
You might also like to view...
(Mortgage Calculator Application) A bank offers mortgages that can be repaid in 10, 15, 20, 25 or 30 years. Write an application that allows a user to enter the amount of the mort- gage and the annual interest rate. When the user clicks a JButton, the application displays a table of the mortgage length in years together with the monthly payment as shown in Fig. 8.24.
```
a) Copying the template to your working directory. Copy the directory C:Examples Tutorial08ExercisesMortgageCalculator2 to your C:SimplyJava directory.
b) Opening the template file. Open the MortgageCalculator.java file in your text editor.
c) Customizing a JTextArea. After line 109, insert a statement that sets the bounds property of outputJTextArea to 16, 96, 298, 110. On the next line, add a statement that sets the editable property of outputJTextArea to false.
d) Adding code to the Calculate JButton event handler. Add the code specified in the steps e through m to the calculateJButtonActionPerformed event handler, which begins at line 134.
e) Declaring variables required to determine monthly payments. In calculateJBut- tonActionPerformed, declare int variable years and initialize its value to 10. Also, declare int variable months and double variable monthlyPayment.
f) Obtaining the user input and converting the annual interest rate to the monthly interest
One way to select colors is to use the ____ to open the color palette, and enter a color's hexadecimal value or create custom colors.
A. Color manager B. Color wizard C. Color editor D. Color panel
Which of the following is TRUE regarding the AutoNumber data type?
A) An AutoNumber is a field added to a table to serve as a foreign key that is unique and sequential when records are created. B) A random AutoNumber is the most common and is the default setting in Access when selecting the AutoNumber data type. C) A sequential AutoNumber will generate a random number that is unique to each record within the table. D) AutoNumbers are a great method for ensuring that records are uniquely identified.
Categorize the following as simple random sampling, stratified sampling, systematic sampling, cluster sampling, or convenience sampling. An instructor at a community college teaches five classes in a semester. Two of the classes are chosen by the dean and all students in those classes fill out an instructor evaluation form about that instructor.
A. convenience sampling B. stratified sampling C. cluster sampling D. systematic sampling E. simple random sampling