CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    0

    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.

  2. #2
    Join Date
    Sep 2011
    Posts
    6

    Re: Need help with maths problem in C#

    Quote Originally Posted by nicholas68 View Post
    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

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help with maths problem in C#

    Please use [code][/code] tags when posting code.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Sep 2011
    Posts
    6

    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
  •  





Click Here to Expand Forum to Full Width

Featured