Assignment #2: Loop 1
Assignment #2: Loop 1
Create a Windows Forms Application that performs some while loops, if-else statements and double
type calculations.
Loop 1
Inside a panel, use labels and textboxes to get a starting number and an ending number from
the user to be used for the loop.
Insert a button called Go that will run the loop, and an output label that will display
information once the loop is done.
Insert a button beside the start number textbox called Is Prime?
Part 1
Use the double type for all mathematical variables.
Create a while loop using the first textbox as the starting number. Incrementing by 1, run the loop until
you reach the value of the end number (from the second textbox).
Use an if-else statement to determine if a number is odd or even. Use this method below which returns
a Boolean (true or false).
Part 3 Calculations
Create a double type variable that calculates the average of all the numbers in the loop. Ex) sum of all
the numbers / number of times through loop.
Create a double type variable that takes the average and divides it by the sum of all the numbers.
Format both doubles to have 2 decimal places. Ex) average.ToString(F2)
Part 4
Display all the results onto the output label like so:
Part 5
When the Is Prime? button is clicked, send a message to the user via the MessageBox.Show command
that tells them if the start number is a prime number or not. Use an if-else statement to determine this.
Use the method below to determine if the number is a prime or not. It returns a Boolean (true or false).
Inside a panel, use labels and textboxes to get an ending number from the user to be used for
the loop.
Insert a button called Go that will start the loop.
Insert a Progress Bar
Insert a BackgroundWorker
Insert an output label that will display information once the loop is done.
Part 2
Create a while loop using the textbox as the ending number. Starting at 1, increment by 1 until you
reach the value of the end number.
Set the progress bar maximum to the value of textbox (end number).
Put a System.Threading.Thread.Sleep(500); inside your loop to create a small pause each time through.
Part 3
In the backgroundworker processchanged method, output the current Date and Time to the output
label. To get the current Date and Time use DateTime.Now.ToString().