1
        private int Calculate(int x, int y, Operation operation) {
            switch (operation) {
                case Operation.PLUS:
                    return x + y;
                case Operation.MINUS:
                    return x - y;
                case Operation.DIVIDE:
                    return x / y;
                case Operation.MULTIPLY:
                    return x * y;
                case Operation.PERCENT:
                    double number = x;
                    double percent = y;
                    double result = number * (percent / 100);
                    return (int)Math.Round(result);
                case Operation.ERROR:
                    return -1;
            }
            return -2;
        }

Предоставляю код, который вычисляет проценты, со всем остальным проблем нет. Для примера, вводимое число 500, проценты - 50. И вместо числа 250 выходит 25000. Не могу понять в чём проблема

1
  • 1
    Не воспроизводится int x = 100, y = 5; double number = x; double percent = y; double result = number * (percent / 100); int pp = (int)Math.Round(result); 16 апр 2019 в 16:55

1 ответ 1

4

Все срабатывает как надо:

int x = 500;
int y = 50;
Console.WriteLine(System.Math.Round((double)(x * y / 100)));

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.