double a, ostanek;
a=Convert.ToDouble(Console.ReadLine());
int apoen_500, apoen_200, apoen_100, apoen_50, apoen_20, apoen_10, apoen_5, apoen2, apoen1;
int ost50cent, ost20cent, ost10cent, ost5cent, ost2cent, ost1cent;
apoen_500 = (int)a/500;
ostanek = a%500;
apoen_200=(int)ostanek/200;
ostanek = ostanek % 200;
apoen_100 = (int)ostanek/100;
ostanek = ostanek % 100;
apoen_50 = (int)ostanek/50;
ostanek = ostanek % 50;
apoen_20 = (int)ostanek/20;
ostanek = ostanek % 20;
apoen_10 = (int)ostanek/10;
ostanek = ostanek % 10;
apoen_5 = (int)ostanek /5 ;
ostanek = ostanek % 5;
apoen2 = (int)ostanek/2;
ostanek = ostanek % 2;
apoen1 = (int)ostanek/1;
ostanek = ostanek % 1;
ost50cent = (int)(ostanek/0.50);
ostanek = ostanek % 0.50;
ost20cent = (int)(ostanek/0.20);
ostanek = ostanek % 0.20;
ost10cent = (int)(ostanek/0.10);
ostanek = ostanek % 0.10;
ost5cent = (int)(ostanek/0.05);
ostanek = ostanek % 0.05;
ost2cent = (int)(ostanek/0.02);
ostanek = ostanek % 0.02;
ost1cent = (int)(ostanek/0.01);
ostanek = ostanek % 0.01;
Console.WriteLine(apoen_500 +"x500");
Console.WriteLine(apoen_200 + "x200");
Console.WriteLine(apoen_100 + "x100");
Console.WriteLine(apoen_50 + "x50");
Console.WriteLine(apoen_20 + "x20");
Console.WriteLine(apoen_10 + "x10");
Console.WriteLine(apoen_5 + "x5");
Console.WriteLine(apoen2 + "x2");
Console.WriteLine(apoen1 + "x1");
Console.WriteLine(ost50cent + "x50 centov");
Console.WriteLine(ost20cent + "x20 centov");
Console.WriteLine(ost10cent + "x10 centov");
Console.WriteLine(ost5cent + "x5 centov");
Console.WriteLine(ost2cent + "x2 centov");
Console.WriteLine(ost1cent + "x1 centov");
У меня есть этот код, но он не работает, как планировалось. Он суетится, чтобы разделить деньги на более мелкие кусочки, но он не работает для 50, 20, 10, 5, 2 1 центов. Он отображается неправильно. Например, если я нахожу 90,75, он отображает 1x50 € 1x 20 € 1x50c 1x20c 2x 2 цента, но он должен быть 1x5 центов.Программа деления на деньги C#
Вы не можете использовать двойники для финансовых расчетов. Равенство и модальные операции часто ведут себя неожиданно. Вместо этого используйте тип «decimal». – Matthew
С чем я его использую? –
decimal a = Convert.ToDecimal(); – alexm