Link to home
Start Free TrialLog in
Avatar of kensy11
kensy11Flag for Belgium

asked on

C# point numbers

Hello,

i have made a program it ask for a money amount .
and it spits the money for example , If you give 150 its wil says:

1 X 100
1X 50

But when i try to use 150,20 cent

it doesn't work , i don't know what im doing wrong or what i need to do?


Program.cs
using System;

namespace ConsAppl1TI34 {
  class Program {
    static void Main(string[] args) {
      ConsCode Cc = new ConsCode();
      Cc.ExecuteProgram();
      Console.ReadKey(true);
    }/*Main*/
  }/*Program*/
}/*ConsAppl1TI34*/

Open in new window


ConsCode.cs
using System;

namespace ConsAppl1TI34 {
  class ConsCode {
      public void ExecuteProgram() {
      decimal Bedrag;
      uint Nr500, Nr200, Nr100, Nr50, Nr20, Nr10, Nr5, Nr2, Nr1, Nr50c, Nr20c, Nr10c, Nr5c, Nr2c, Nr1c;
      ClsMoney Cm = new ClsMoney();
      Console.Title = "Opgave 10: Splitsing geldbedrag (zonder tabel)";
      Bedrag = GiveAmount();
      Cm.SplitAmount(Bedrag, out Nr500, out Nr200, out Nr100, out Nr50, out Nr20, out Nr10, out Nr5,
      out Nr2, out Nr1, out Nr50c, out Nr20c, out Nr10c, out Nr5c, out Nr2c, out Nr1c);
      DisplayResult(Bedrag, Nr500, Nr200, Nr100, Nr50, Nr20, Nr10, Nr5,
      Nr2, Nr1, Nr50c, Nr20c, Nr10c, Nr5c, Nr2c, Nr1c);
      }/*ExecuteProgram*/

      public void DisplayResult(decimal Bedrag, uint Nr500, uint Nr200, uint Nr100, uint Nr50, uint Nr20, uint Nr10, uint Nr5, uint Nr2, uint Nr1, uint Nr50c, uint Nr20c, uint Nr10c, uint Nr5c, uint Nr2c, uint Nr1c) {
        Console.WriteLine("Een bedrag van {} Euro wordt het kortst verdeeld als:");


        Console.WriteLine("{0} X 500", Nr500);
        Console.WriteLine("{0} X 200", Nr200);
        Console.WriteLine("{0} X 100", Nr100);
        Console.WriteLine("{0} X 50", Nr50);
        Console.WriteLine("{0} X 20", Nr20);
        Console.WriteLine("{0} X 10", Nr10);
        Console.WriteLine("{0} X 5", Nr5);
        Console.WriteLine("{0} X 2", Nr2);
        Console.WriteLine("{0} X 1", Nr1);
        Console.WriteLine("{0} X 0,50", Nr50c);
        Console.WriteLine("{0} X 0,20", Nr20c);
        Console.WriteLine("{0} X 0,10", Nr10c);
        Console.WriteLine("{0} X 0,05", Nr5c);
        Console.WriteLine("{0} X 0,02", Nr2c);
        Console.WriteLine("{0} X 0,01", Nr1c);

      }
      public decimal GiveAmount()
      {
 	      Console.WriteLine("Geef een bedrag in euro in a.u.b ...");
        decimal GiveAmount = decimal.Parse(Console.ReadLine());
        return GiveAmount;
      }/*GiveAmount*/
  }/*ConsCode*/
}/*ConsAppl1TI34*/

Open in new window



ClsMoney.cs
using System;

namespace ConsAppl1TI34 {
  class ClsMoney {

    public void SplitAmount(decimal Bedrag, out uint Nr500, out uint Nr200, out uint Nr100, out uint Nr50, out uint Nr20, out uint Nr10, out uint Nr5,
      out uint Nr2, out uint Nr1, out uint Nr50c, out uint Nr20c, out uint Nr10c, out uint Nr5c, out uint Nr2c, out uint Nr1c){
      
      Nr500 = 0;
      Nr200 = 0;
      Nr100 = 0;
      Nr50 = 0;
      Nr20 = 0;
      Nr10 = 0;
      Nr5 = 0;
      Nr2 = 0;
      Nr1 = 0;
      Nr50c = 0;
      Nr20c = 0;
      Nr10c = 0;
      Nr5c = 0;
      Nr2c = 0;
      Nr1c = 0;

        while (Bedrag > 500) {

          Nr500 = Convert.ToUInt32(Math.Floor(Bedrag / 500));
          Bedrag = Bedrag % 500;
        }

        while (Bedrag >= 200) {

          Nr200 = Convert.ToUInt32(Math.Floor(Bedrag / 200));
          Bedrag = Bedrag % 200;
        }

        while (Bedrag >= 100) {

          Nr100 = Convert.ToUInt32(Math.Floor(Bedrag / 100));
          Bedrag = Bedrag % 100;
        }

        while (Bedrag >= 50) {

          Nr50 = Convert.ToUInt32(Math.Floor(Bedrag / 50));
          Bedrag = Bedrag % 50;
        }

        while (Bedrag >= 20) {

          Nr20 = Convert.ToUInt32(Math.Floor(Bedrag / 20));
          Bedrag = Bedrag % 20;
        }
        while (Bedrag >= 10) {

          Nr10 = Convert.ToUInt32(Math.Floor(Bedrag / 10));
          Bedrag = Bedrag % 10;
        }
        while (Bedrag >= 5) {

          Nr5 = Convert.ToUInt32(Math.Floor(Bedrag / 5));
          Bedrag = Bedrag % 5;
        }
        while (Bedrag >= 2) {

          Nr2 = Convert.ToUInt32(Math.Floor(Bedrag / 2));
          Bedrag = Bedrag % 2;
        } while (Bedrag >= 1) {

          Nr1 = Convert.ToUInt32(Math.Floor(Bedrag / 1));
          Bedrag = Bedrag % 1;
        } while (Bedrag >= 1) {

          Nr1 = Convert.ToUInt32(Math.Floor(Bedrag / 1));
          Bedrag = Bedrag % 1;
        }
        while (Bedrag >= 0.50m) {

          Nr50c = Convert.ToUInt32(Bedrag / 0.50m);
          Bedrag = Bedrag % 1;
          
        }
    }
  }
}

Open in new window

You can download the program

thank you
Opgave-02.zip
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kensy11

ASKER

Yes we use , instead of .

but how can i use '.' point when i use point instead of a ',' i get something else

fore example when i give 150.20 it thinks its 15020 euro
but when i use ',' it does the tight thing so its 150 euro and 20 cent

Thank you
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I asked just to verify the code usage in case I miss a special case. (I tested with my current settings that uses the dot(.) and it was working fine anyway)
That is OK, you just confirmed that your regional settings use the comma to represent decimals.