С# Ошибка переключения калькулятора простых процентов

Я пытаюсь сделать простой калькулятор процентов, в котором человек вводит число (1-4) для того, что он хочет рассчитать, затем вводит заданные числа и получает недостающую переменную.

код:

using System;
using System.Convert;

public class InterestCalculator {
    static public void Main(string [] args) {
        int final, initial, rate, time, input;

        Console.WriteLine("What do you want to calculate? \n 1. Final amount after interest. \n 2. Initial amount after interest. \n 3. Interest rate. \n 4. Time passed");
        input = Convert.ToInt32(Console.ReadLine());
        switch (input){
            case 1:
                Console.WriteLine("Enter the initial amount.");
                initial = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the interest rate.");
                rate = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the time passed.");
                time = Convert.ToInt32(Console.ReadLine());
                final = initial * rate * time;
                Console.WriteLine("$" + final + " is the final amount after interest.");
                break;
            case 2:
                Console.WriteLine("Enter the final amount.");
                final = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the interest rate.");
                rate = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the time passed.");
                time = Convert.ToInt32(Console.ReadLine);
                initial = final/(rate * time);
                Console.WriteLine("$" + initial + " is the initial amount before interest.");
                break;
            case 3:
                Console.WriteLine("Enter the final amount.");
                final = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the initial amount.");
                initial = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the time passed.");
                time = Convert.ToInt32(Console.ReadLine);
                rate = final/(initial * time);
                Console.WriteLine("%" + initial + " per time cycle is the interest rate");
                break;
            case 4:
                Console.WriteLine("Enter the final amount.");
                final = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the initial amount.");
                initial = Convert.ToInt32(Console.ReadLine);
                Console.WriteLine("Enter the interest rate.");
                rate = Convert.ToInt32(Console.ReadLine());
                time = final/(initial * rate);
                Console.WriteLine(initial + " cycles is the amount of time passed.");
                break;}
            default:
                Console.WriteLine("Invalid input.");
        }
    }
}

Я продолжаю получать эту ошибку в процессе компиляции (используя моно):

error CS1502: The best overloaded method match for System.Convert.ToInt32(bool) has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'
error CS1502: The best overloaded method match for `System.Convert.ToInt32(bool)' has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'
error CS1502: The best overloaded method match for `System.Convert.ToInt32(bool)' has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'

person Zunon    schedule 09.02.2015    source источник
comment
в вашем коде всегда меняйте: initial = Convert.ToInt32(Console.ReadLine); в начальный = Convert.ToInt32(Console.ReadLine()); и сделать то же самое со временем   -  person Tomer Klein    schedule 09.02.2015
comment
Я также советую вам не использовать слово "final" в качестве имени переменной, просто для хорошей практики (потому что это ключевое слово). Наконец, никогда не пытайтесь напрямую преобразовать ввод пользователя в целое число. Приложение вылетит, если вы введете нечисловое значение.   -  person Tarske    schedule 09.02.2015
comment
@Tarske Хотя я согласен с вами в том, что ключевые слова не используются в качестве идентификаторов, я не вижу ничего плохого в использовании здесь final, поскольку это не ключевое слово в C#.   -  person Bill Tür    schedule 09.02.2015
comment
@ThomasSchremser К сожалению, вы правы. Приносим свои извинения и спасибо за исправление.   -  person Tarske    schedule 10.02.2015


Ответы (2)


Ну, у одного из ваших Console.ReadLine() нет скобок. Таким образом, вы передаете метод, а не вызываете его.

person Nathan Cooper    schedule 09.02.2015
comment
Я пока насчитал три. - person B.K.; 09.02.2015

Большинство мест у вас есть только

Console.ReadLine вместо Console.ReadLine()

Проверьте код. Например -

Случай 2

time = Convert.ToInt32(Console.ReadLine);

Исправьте все эти строки.

Кроме того, предлагается сначала ввести данные в локальную переменную, а затем попытаться преобразовать.

person Amit    schedule 09.02.2015