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

C#

 
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 
Depends on the requirements.

I personally try not to throw exceptions unless it makes sense to do so. You don't have to return additional info.

In this case, overdrafts might be allowed (if they are, you can also specify an overdraft limit, but I leave that as an exercise for you).

C#
public decimal MakeWithdraw(ref decimal balance, decimal amount, bool allowOverdraft=false)
{
    decimal widthdrawn = (amount <= balance) ? amount : ((allowOverdraft) ? amount : balance);
    balance -= withdrawn;
    return widthdrawn;
}


BTW, using decimal instead of double is a good idea because math performed on doubles is not as accurate as math performed on decimals.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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 
GeneralRe: How to programmatically paste text into a specific Word document Pin
Leif Simon Goodwin7-Feb-18 3:46
Leif Simon Goodwin7-Feb-18 3:46 

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.