CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 21

Threaded View

  1. #1
    Join Date
    Feb 2013

    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.
    public partial class frmInvoiceTotal : Form
    		public frmInvoiceTotal()
            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");
                totalOfInvoices += invoiceTotal;
                invoiceAverage = totalOfInvoices / numberOfInvoices;
                txtNumberOfInvoices.Text = numberOfInvoices.ToString();
                txtTotalOfInvoices.Text = totalOfInvoices.ToString("c");
                txtInvoiceAverage.Text = invoiceAverage.ToString("c");
                txtEnterSubtotal.Text = "";
            private void btnClearTotals_Click(object sender, System.EventArgs e)
                numberOfInvoices = 0;
                totalOfInvoices = 0m;
                invoiceAverage = 0m;
                txtNumberOfInvoices.Text = "";
                txtTotalOfInvoices.Text = "";
                txtInvoiceAverage.Text = "";
            private void btnExit_Click(object sender, EventArgs e)
            private void label10_Click(object sender, EventArgs e)
    Last edited by BioPhysEngr; February 3rd, 2013 at 12: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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.