Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
: Form
public frmInvoiceTotal
InitializeComponent
;
private void btnCalculate
Click
object sender
EventArgs e
string customerType
txtCustomerTypeText;
decimal subtotal
ConvertToDecimal
txtSubtotal
Text
;
decimal discountPercent
m;
switch
customerType
case
R
:
if
subtotal
discountPercent
m;
else if
subtotal
&& subtotal
discountPercent
m;
else if
subtotal
&& subtotal
discountPercent
m;
else if
subtotal
discountPercent
m;
break;
case
C
:
discountPercent
m;
break;
case
T
:
if
subtotal
discountPercent
m;
else
discountPercent
m;
break;
default:
discountPercent
m;
break;
decimal discountAmount
subtotal
discountPercent
;
decimal invoiceTotal
subtotal
discountAmount;
txtDiscountPercent.Text
discountPercentToString
p
;
txtDiscountAmount.Text
discountAmountToString
c
;
txtTotal.Text
invoiceTotalToString
c
;
private void btnExit
Click
object sender
EventArgs e
this.Close
;
private void frmInvoiceTotal
Load
object sender
EventArgs e
txtSubtotal.Text
;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started