Trade_Comissions
при вход ;
пловдив
-20
изхода трябва да е error но при мин е 20,00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Trade_Comissions
{
class Program
{
static void Main(string[] args)
{
string sity = Console.ReadLine().ToLower();
double sales = double.Parse(Console.ReadLine());
double comission = -1;
if (sity == "sofia")
{
if (0 <= sales && sales <= 500) comission = 0.05;
else if (500 < sales && sales <= 1000) comission = 0.07;
else if (1000 < sales && sales <= 10000) comission = 0.08;
else if (sales > 10000) comission = 0.12;
{
Console.WriteLine($"{(comission * sales):f2}");
}
}
else if (sity == "varna")
{
if (0 <= sales && sales <= 500) comission = 0.045;
else if (500 < sales && sales <= 1000) comission = 0.075;
else if (1000 < sales && sales <= 10000) comission = 0.10;
else if (sales > 10000) comission = 0.13;
{
Console.WriteLine($"{(comission * sales):f2}");
}
}
else if (sity == "plovdiv")
{
if (0 <= sales && sales <= 500) comission = 0.055;
else if (500 < sales && sales <= 1000) comission = 0.08;
else if (1000 < sales && sales <= 10000) comission = 0.12;
else if (sales > 10000) comission = 0.145;
{
Console.WriteLine($"{(comission * sales):f2}");
}
}
else if (sales < 0 || sity != "sofia" || sity != "plovdiv" || sity != "varna")
{
Console.WriteLine("error");
}
}
}
}
благодаря ! качих го горе но само това
if (sales < 0)
{
Console.WriteLine("error");
}
Няма нужда само това if (sales < 0) да качваш горе, просто го направи така:
if (sales < 0 || sity != "sofia" || sity != "plovdiv" || sity != "varna" || sales < 0)
{
Console.WriteLine("error");
}
По този начин няма да имаш две проверки, няма да дублираш код.