I did a task from one famous course. The task is that we have a debt and we can pay it immediately or in parts. But the condition is that your next payment should be more than the previous one. I coped with the task itself, but looking at the code, I think that it is very complicated and complicated.
Here he is:
using System; class Program { static void Main() { int maxSum = 700; int payment = 0; int previousPayment = 0; int moneyToPay = 0; while(maxSum != 0) { do { Console.WriteLine("Введите сумму платежа"); payment = int.Parse(Console.ReadLine()); //previousPayment = payment; moneyToPay = debt(payment, ref maxSum, ref previousPayment); if (moneyToPay == 0) { break; } } while (false); if(moneyToPay == -1) { break; } } Console.ReadKey(); } static int debt(int a,ref int maxSum, ref int previousPayment) { if (a == maxSum) { Console.WriteLine("Долг погашен"); return maxSum = 0; } else if (a < maxSum) { int Debt = maxSum - a; if(a < previousPayment) { Console.WriteLine("Вы должны оплатить сумму больше чём {0}", previousPayment); return -1; } Console.WriteLine("Ваш долг составляет:{0}", Debt); maxSum = Debt; previousPayment = a; return Debt; } else { Console.WriteLine("Долг погашен"); Console.WriteLine("Переполнение составляет:{0}", a - maxSum); return maxSum = 0; } } }
do{...}while(false)? - Grundyref maxSum- tCode