Debug the following program Each line that has a number and
Debug the following program. Each line that has a number and line at the end of it has an error. The error can be syntax or logic. Correct the error. Rewrite the correct answer in place of the original code (30 points):
private void btnCalculate_Click (object sender, System.EventArgs e)
This is ok
(
This is #1
int intLimit = zero; // upper limit set by user
This is #2
int intCounter == 1; // counter begins at 1
This is #3
lstResults.Items.Empty(); // clear ListBox
This is #4
intLimit = Int32.Parse( txtInput); // retrieve user input from GUI
This is #5
lstResults.Items.Add( \"N/tN^2/tN^3\" ); // add header with tabs
This is #6
// calculate and display square and cube of 1 to intLimit
while ( intCounter <= intLimit ) ;
This is #7
{
lstResults.Items.Add( intCounter = \"\\t\" + Math.Pow( intCounter, 2 ) + \"\\t\" +
Math.Pow( intCounter, 3 ) );
This is # 8
intCounter--; // increment counter
This is # 9
)
This is #10
Solution
Here is the modified code given here wiht corrected Syntax
private void btnCalculate_Click (object sender, System.EventArgs e)
This is ok
( // modify it as {
This is #1
int intLimit = zero; // upper limit set by user // modify this as int intLimit =0;
This is #2
int intCounter == 1; // counter begins at 1 // modify this as int intCounter =1
This is #3
lstResults.Items.Empty(); // clear ListBox // modify this as 1stResults.getItems().clear();
This is #4
intLimit = Int32.Parse( txtInput); // retrieve user input from GUI // modify this as Iteger.parseInt(txtInput);
This is #5
lstResults.Items.Add( \"N/tN^2/tN^3\" ); // add header with tabs // modify this as lstResults.Items.Add( N + \"\\t \" + N^2 + \"\\t\" +N^3 );
This is #6
// calculate and display square and cube of 1 to intLimit
while ( intCounter <= intLimit ) ; // modify this as while ( intCounter <= intLimit )
This is #7
{
lstResults.Items.Add( intCounter = \"\\t\" + Math.Pow( intCounter, 2 ) + \"\\t\" + Math.Pow( intCounter, 3 ) );
// modify this as lstResults.Items.Add( intCounter + \"= \\t\" + Math.Pow( intCounter, 2 ) + \"\\t\" + Math.Pow( intCounter, 3 ) );
This is # 8
intCounter--; // increment counter // modify this as intCounter++;
This is # 9
) // modify this as }
This is #10

