-
February 2nd, 2013, 09:15 PM
#1
Find Minimum and Maximum values
I have a form that has people enter an amount, and it calculates a discount for the invoice and displays it, as well as total of all invoices, number of invoices, and average invoice amount. I need it to also display the smallest and largest invoices. I am still quite new to C#, so any hints would be greatly appreciated. Here's the code I have so far, not sure how to start on the last part, looking into using Math.Max and Math.Min.
Code:
public partial class frmInvoiceTotal : Form
{
public frmInvoiceTotal()
{
InitializeComponent();
}
int numberOfInvoices = 0;
decimal totalOfInvoices = 0m;
decimal invoiceAverage = 0m;
private void btnCalculate_Click(object sender, EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtEnterSubtotal.Text);
decimal discountPercent = .25m;
decimal discountAmount = Math.Round(subtotal * discountPercent, 2);
decimal invoiceTotal = subtotal - discountAmount;
txtEnterSubtotal.Text = subtotal.ToString("c");
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");
numberOfInvoices++;
totalOfInvoices += invoiceTotal;
invoiceAverage = totalOfInvoices / numberOfInvoices;
txtNumberOfInvoices.Text = numberOfInvoices.ToString();
txtTotalOfInvoices.Text = totalOfInvoices.ToString("c");
txtInvoiceAverage.Text = invoiceAverage.ToString("c");
txtEnterSubtotal.Text = "";
txtEnterSubtotal.Focus();
}
private void btnClearTotals_Click(object sender, System.EventArgs e)
{
numberOfInvoices = 0;
totalOfInvoices = 0m;
invoiceAverage = 0m;
txtNumberOfInvoices.Text = "";
txtTotalOfInvoices.Text = "";
txtInvoiceAverage.Text = "";
txtEnterSubtotal.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void label10_Click(object sender, EventArgs e)
{
}
}
}
Last edited by BioPhysEngr; February 3rd, 2013 at 01:20 AM.
Reason: add code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|