Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Richard MacCutchan7-Feb-18 23:13
mveRichard MacCutchan7-Feb-18 23:13 
AnswerRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL PinPopular
Eddy Vluggen8-Feb-18 1:18
professionalEddy Vluggen8-Feb-18 1:18 
QuestionHow can I enumerate through OU's for nodes and add them to an existing treeview root node? Pin
turbosupramk37-Feb-18 10:35
turbosupramk37-Feb-18 10:35 
AnswerRe: How can I enumerate through OU's for nodes and add them to an existing treeview root node? Pin
BillWoodruff7-Feb-18 16:53
professionalBillWoodruff7-Feb-18 16:53 
Question(beginner question) help with code for a project Pin
Member 136645666-Feb-18 11:14
Member 136645666-Feb-18 11:14 
AnswerRe: (beginner question) help with code for a project Pin
Eddy Vluggen6-Feb-18 14:34
professionalEddy Vluggen6-Feb-18 14:34 
AnswerRe: (beginner question) help with code for a project Pin
Richard MacCutchan6-Feb-18 23:18
mveRichard MacCutchan6-Feb-18 23:18 
GeneralRe: (beginner question) help with code for a project Pin
Member 136645667-Feb-18 3:21
Member 136645667-Feb-18 3:21 
Thanks! I finished the assignment but I am quite sure that my code is very poorly written. I need help cleaning it up. I feel like it can be written with fewer variables and cleaner, fewer lines of code. (Also, to the guy who refers to himself as a "prick", I wasn't sure how to implement that thing into my code. I tried but I got an error. I do not know what that is. Thanks for your help though!)
Here's what I have so far!! (it works perfectly, as an application):

namespace Software_Sales
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void calculateButton_Click(object sender, EventArgs e)
        {
            //declaring the amount each unit costs
            const double PACKAGE_COST_double = 99;

            //declaring the discount rate variables
            const double FIFTY_PCT_double = .5;
            const double FORTY_PCT_double = .4;
            const double THIRTY_PCT_double = .3;
            const double TWENTY_PCT_double = .2;
            const double ZERO_PCT_double = 0;

            
            double retail;  //holds the cost without any discount
            double discountrate; //to hold the discount rate for discountLabel
            double saved;        //to hold the amount saved
            double total;        //to hold the total after discount
            int purchased;    //to hold the purchased units   

            purchased = int.Parse(purchasedTextBox.Text);

            //calculate the data from purchasedTextBox
            try
            {
                //get the # of purchased units
                purchased = int.Parse(purchasedTextBox.Text);

                //if the purchased units are greater than or equal to 100,
                //put 50% in the first label
                if (purchased >= 100)
                {
                    discountrate = .5;
                    saved = (purchased * PACKAGE_COST_double) * FIFTY_PCT_double;
                    retail = purchased * PACKAGE_COST_double;
                    total = retail - saved;

                }
                //if the purchased units are greater than or equal to 50,               
                //but less than or equal to 99, put 40% in the first label
                else if (purchased >= 50)
                {
                    discountrate = .4;
                    saved = (purchased * PACKAGE_COST_double) * FORTY_PCT_double;
                    retail = purchased * PACKAGE_COST_double;
                    total = retail - saved;

                }
                //if the purchased units are greater than or equal to 20, 
                //or less than or equal to 49, use 30% in the first label
                else if (purchased >= 20)
                {
                    discountrate = .3;
                    saved = (purchased * PACKAGE_COST_double) * THIRTY_PCT_double;
                    retail = purchased * PACKAGE_COST_double;
                    total = retail - saved;

                }
                //if the purchased amount is less than or equal to 19 
                //or greater than or equal to 10, use %20 in the first label
                else if (purchased >= 10)
                {
                    discountrate = .2;
                    saved = (purchased * PACKAGE_COST_double) * TWENTY_PCT_double;
                    retail = purchased * PACKAGE_COST_double;
                    total = retail - saved;

                }
                //if the purchased amount is between 0 and 10 or equal, the discount is 0%
                else
                {
                    discountrate = 0;
                    saved = (purchased * PACKAGE_COST_double) * ZERO_PCT_double;
                    retail = purchased * PACKAGE_COST_double;
                    total = retail - saved;
                }

                discountLabel.Text = string.Format("{0}%", discountrate * 100);
                totalLabel.Text = total.ToString("c"); 
                total = retail - saved;
                retail = purchased * PACKAGE_COST_double;
                savedLabel.Text = saved.ToString("c");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

GeneralRe: (beginner question) help with code for a project Pin
Richard MacCutchan7-Feb-18 3:31
mveRichard MacCutchan7-Feb-18 3:31 
GeneralRe: (beginner question) help with code for a project Pin
Member 136645667-Feb-18 5:00
Member 136645667-Feb-18 5:00 
GeneralRe: (beginner question) help with code for a project Pin
Richard MacCutchan7-Feb-18 5:13
mveRichard MacCutchan7-Feb-18 5:13 
GeneralRe: (beginner question) help with code for a project Pin
Gerry Schmitz7-Feb-18 5:29
mveGerry Schmitz7-Feb-18 5:29 
QuestionDesign-Question: Using ReturnValue or Throwing Exception Pin
Frygreen6-Feb-18 11:06
Frygreen6-Feb-18 11:06 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
Richard Andrew x646-Feb-18 12:17
professionalRichard Andrew x646-Feb-18 12:17 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
Eddy Vluggen6-Feb-18 15:06
professionalEddy Vluggen6-Feb-18 15:06 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
OriginalGriff6-Feb-18 23:21
mveOriginalGriff6-Feb-18 23:21 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
#realJSOP7-Feb-18 3:56
professional#realJSOP7-Feb-18 3:56 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
Gerry Schmitz7-Feb-18 5:45
mveGerry Schmitz7-Feb-18 5:45 
AnswerRe: Design-Question: Using ReturnValue or Throwing Exception Pin
Frygreen7-Feb-18 14:11
Frygreen7-Feb-18 14:11 
QuestionNunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Frygreen6-Feb-18 9:35
Frygreen6-Feb-18 9:35 
AnswerRe: Nunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Pete O'Hanlon6-Feb-18 10:10
mvePete O'Hanlon6-Feb-18 10:10 
GeneralRe: Nunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Frygreen6-Feb-18 10:32
Frygreen6-Feb-18 10:32 
AnswerRe: Nunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Gerry Schmitz7-Feb-18 5:54
mveGerry Schmitz7-Feb-18 5:54 
GeneralRe: Nunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Frygreen7-Feb-18 14:32
Frygreen7-Feb-18 14:32 
GeneralRe: Nunit3: Debug of Testcases. => No breakpoints hit with console-runner Pin
Gerry Schmitz7-Feb-18 14:47
mveGerry Schmitz7-Feb-18 14:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.