Проверка кода на гавнокод и его оптимизация - C#
Формулировка задачи:
Здраствуйте! я начию програмировать и пишу совсем несложный код, но хочу спросить у знающих как мне правильно его оптимизировать и убрать/добавить что-то. Хочу сразу учиться грамотно писать и поэтому я здесь)
Так вот, предпоссылкой к этому коду стало пополнение счета телефона через терминал. Вот так вот сам себе придумал, я думаю с кода станет всё ясно.
using System;
namespace ReplenishmentPhone
{
class Program
{
static void Main(string[] args)
{
double commision;
bool exit = true;
Console.WriteLine("Welcome to cash opperation");
Console.WriteLine();
Console.WriteLine("\n0.01 to 4.99 grn commision = 3%" +
"\n5.00 to 14.99 grn commision = 3.5%"+
"\n15.00 to more commision = 4%");
Console.WriteLine();
while (exit)
{
Console.Write("Insert your cash: ");
double cash = Convert.ToDouble(Console.ReadLine());
if (cash <= 4.99)
{
commision = cash / 100 * 3;
cash = cash - commision;
Console.WriteLine("Credited to your account: {0} grn \nCommision = {1} grn", cash, commision);
}
else if (cash <= 5.00 & cash >= 14.99 )
{
commision = cash / 100 * 3.5;
cash = cash - commision;
Console.WriteLine("Credited to your account: {0} grn \nCommision = {1} grn", cash, commision);
}
else if (cash >= 15.00)
{
commision = cash / 100 * 4;
cash = cash - commision;
Console.WriteLine("Credited to your account: {0} grn \nCommision = {1} grn", cash, commision);
}
Console.WriteLine();
Console.WriteLine("Do you want to Pay more? ");
string askToExit = Console.ReadLine();
if (askToExit == "n")
{
Console.WriteLine("Spa-si-bo za to sho pi4kalu v nas bablo");
exit = false;
}
}
Console.ReadLine();
}
}
}Решение задачи: «Проверка кода на гавнокод и его оптимизация»
textual
Листинг программы
commision = cash / 100 * 3; cash = cash - commision;