-
September 5th, 2011, 01:38 AM
#1
Need help with maths problem in C#
Ok so currently I am building an ATM in C# console and I'm at the part where i need it to dispense money, I can only use $20 and $50 notes.
So im having trouble making it acepting inputs like $60 and $180 and so on... Cause it tries to use a 50 and then cant use 20's because of the left over remainder. So it needs to be able to figure out if it can only use 20's ($60 for example)
Eventually I'm also going to have to have it say how many of each it is returning, so on the screen i can say please collect 2 $50 notes and 2 $20 notes if they where to input $140. So i guess i need to add something in the code to tell me that.
So if you guys have any ideas please let me know. Maths in coding as never been my strong point as I'm still learning
Ive got some of my own code but i cant get it to work so any suggestions or so on?
Thanks Nick, help is MUCH appreciated.
-
September 7th, 2011, 07:36 PM
#2
Re: Need help with maths problem in C#
Originally Posted by nicholas68
Ok so currently I am building an ATM in C# console and I'm at the part where i need it to dispense money, I can only use $20 and $50 notes.
So im having trouble making it acepting inputs like $60 and $180 and so on... Cause it tries to use a 50 and then cant use 20's because of the left over remainder. So it needs to be able to figure out if it can only use 20's ($60 for example)
Eventually I'm also going to have to have it say how many of each it is returning, so on the screen i can say please collect 2 $50 notes and 2 $20 notes if they where to input $140. So i guess i need to add something in the code to tell me that.
So if you guys have any ideas please let me know. Maths in coding as never been my strong point as I'm still learning
Ive got some of my own code but i cant get it to work so any suggestions or so on?
Thanks Nick, help is MUCH appreciated.
int x; //Let x be the money
int note_50_number=0,note_20_number=0;
if(x%50==0)
{
note_50_number=x/50;
}
else
{
int r=x%50;
if(r%20==0)
{
note_50_number=x/50;
note_20_number=r/20;
}
else
{
if(x%20==0)
{
note_20_number=x/20;
}
else
{
Console.WriteLine("Selected Money can not be lended\n");
}
}
}
Console.WriteLine();// print note_50_number and note_20_number
-
September 8th, 2011, 12:04 PM
#3
Re: Need help with maths problem in C#
Please use [code][/code] tags when posting code.
Always use [code][/code] tags when posting code.
-
September 8th, 2011, 08:13 PM
#4
Re: Need help with maths problem in C#
I did [code=c#][/code] but it was not working. Ok I will use only
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
|