c# - C#简单兴趣计算器切换错误

我正在尝试制作一个简单的兴趣计算器,其中一个人输入要计算的数字(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.");
        }
    }
}

我在编译过程中不断收到此错误(使用mono):
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'

最佳答案

好吧,你的Console.ReadLine()之一没有括号。因此,您传递的是方法而不是调用它。

https://stackoverflow.com/questions/28404995/

相关文章:

c++ - Visual Studio中D8049错误的原因是什么?

c# - 引用Shell32.dll?

r - 使用 R 包 brms 时出错

c# - 分配的左侧必须是变量属性或索引器

java - 无法访问 org.eclipse.core.runtime.IProgressMoni

c# - 错误: [feature] requires a Business (or higher)

python - 无法运行Python脚本

c# - 具有只读哈希表的嵌套内部类在分配时引发Null ref异常。

oracle - 错误(3,31): PL/SQL: ORA-00984: Column is no

python - 在 Python 中不使用\n 的新行