Question: Windows c# Application: How do I incorporate a loop into the code below? The previous answer had suggestions as to how to use a while

Windows c# Application: How do I incorporate a loop into the code below? The previous answer had suggestions as to how to use a while loop but it was not entered into the code. Please see below for previous answer and code.To add a loop in the provided code, you could consider implementing a loop to handle multiple calculations based on different customer types or multiple invoices. For example, you could use a while loop to continuously prompt the user for input until they choose to exit the application. Here's how you could modify the code to incorporate such a loop:
using System;
using System.Windows.Forms;
namespace InvoiceTotal
{
public partial class frmInvoiceTotal
3
: Form
{
public frmInvoiceTotal
3
(
)
{
InitializeComponent
(
)
;
}
private void btnCalculate
_
Click
(
object sender
,
EventArgs e
)
{
string customerType
=
txtCustomerType.Text;
decimal subtotal
=
Convert.ToDecimal
(
txtSubtotal
.
Text
)
;
decimal discountPercent
=
0
m;
switch
(
customerType
)
{
case
"
R
"
:
if
(
subtotal
<
1
0
0
)
discountPercent
=
0
m;
else if
(
subtotal
>
=
1
0
0
&& subtotal
<
2
5
0
)
discountPercent
=
1
m;
else if
(
subtotal
>
=
2
5
0
&& subtotal
<
5
0
0
)
discountPercent
=
2
5
m;
else if
(
subtotal
>
=
5
0
0
)
discountPercent
=
3
0
m;
break;
case
"
C
"
:
discountPercent
=
2
0
m;
break;
case
"
T
"
:
if
(
subtotal
<
5
0
0
)
discountPercent
=
4
m;
else
discountPercent
=
5
m;
break;
default:
discountPercent
=
0
m;
break;
}
decimal discountAmount
=
subtotal
*
(
discountPercent
/
1
0
0
)
;
decimal invoiceTotal
=
subtotal
-
discountAmount;
txtDiscountPercent.Text
=
discountPercent.ToString
(
"
p
1
"
)
;
txtDiscountAmount.Text
=
discountAmount.ToString
(
"
c
"
)
;
txtTotal.Text
=
invoiceTotal.ToString
(
"
c
"
)
;
}
private void btnExit
_
Click
(
object sender
,
EventArgs e
)
{
this.Close
(
)
;
}
private void frmInvoiceTotal
3
_
Load
(
object sender
,
EventArgs e
)
{
txtSubtotal.Text
=
"
0
.
0
0
"
;
}
}
}
This code sets up a Windows Form application with a loop inside the btnCalculate
_
Click event handler. This loop continues until the user chooses to exit the application. The loop prompts the user for input, calculates the invoice total based on the input, and displays the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!