Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
GeneralRe: (beginner question) help with code for a project Pin
Richard MacCutchan7-Feb-18 3:31
mveRichard MacCutchan7-Feb-18 3:31 
As it is working I suggest you keep it in a safe place . However as I suggested earlier you can simplify your if/else blocks by removing the common code and putting it at the end. Also, why set the discountrate to a hard coded value when you previously declared constants for the various rates? So it could be something like:
C#
    if (purchased >= 100)
    {
        discountrate = FIFTY_PCT_double;
    }
    //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 = FORTY_PCT_double;

    }
    //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 = THIRTY_PCT_double;

    }
    //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 = TWENTY_PCT_double;
    }
    //if the purchased amount is between 0 and 10 or equal, the discount is 0%
    else
    {
        discountrate = ZERO_PCT_double;

    }
    saved = (purchased * PACKAGE_COST_double) * discountrate;
    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
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 
Questionfile checker dump log in C# Pin
Member 136321716-Feb-18 4:34
Member 136321716-Feb-18 4:34 
AnswerRe: file checker dump log in C# Pin
Maciej Los6-Feb-18 5:25
mveMaciej Los6-Feb-18 5:25 
AnswerRe: file checker dump log in C# Pin
Richard MacCutchan6-Feb-18 5:26
mveRichard MacCutchan6-Feb-18 5:26 
AnswerRe: file checker dump log in C# Pin
Dave Kreskowiak6-Feb-18 16:55
mveDave Kreskowiak6-Feb-18 16:55 
QuestionHow to programmatically paste text into a specific Word document Pin
Leif Simon Goodwin6-Feb-18 4:19
Leif Simon Goodwin6-Feb-18 4:19 
AnswerRe: How to programmatically paste text into a specific Word document Pin
Eddy Vluggen6-Feb-18 5:25
professionalEddy Vluggen6-Feb-18 5:25 
GeneralRe: How to programmatically paste text into a specific Word document Pin
Leif Simon Goodwin6-Feb-18 21:51
Leif Simon Goodwin6-Feb-18 21:51 
GeneralRe: How to programmatically paste text into a specific Word document Pin
Eddy Vluggen7-Feb-18 1:31
professionalEddy Vluggen7-Feb-18 1:31 

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.