In: Computer Science
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 :
private void btnCalculate_Click (object sender, System.EventArgs e)
{
intLimit = zero; //
intCounter == 1; // counter need to begin at 1
lstResults.Items.Empty(); // clear ListBox
intLimit = Int32.Parse( txtInput); // retrieve user input from GUI
lstResults.Items.Add( "N/tN^2/tN^3" ); // add header with tabs
calculate and display square and cube of 1 to intLimit
while ( intCounter <= intLimit ) ;
lstbx.Items.Add( intCount = "\t" + Math.Pow( intCount, 2 );
Math.Pow( intCount 3^ );
intCount++; // increment counter
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "WindowsFormsApp7".This application contains a form with name "Form1.cs".Below are the files associated with form1.
1.Form1.cs[Design]
2.Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//calculate button click
private void btnCalculate_Click(object sender, EventArgs e)
{
int intLimit = 0; //declare a variable
int intCounter = 1; // counter need to begin at 1
lstResults.Items.Clear(); // clear ListBox
intLimit = Int32.Parse(txtInput.Text); // retrieve user input from
GUI
lstResults.Items.Add("N\tN^2\tN^3"); // add header with tabs
//calculate and display square and cube of 1 to intLimit
while (intCounter <= intLimit)
{
//find square and cube and add it in the listbox
lstResults.Items.Add(intCounter + "=\t" + Math.Pow(intCounter,
2)+"\t"+Math.Pow(intCounter,3));
intCounter++; // increment counter
}
}
}
}
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2 :Screen showing squares and cubes
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.