小编Phi*_*hil的帖子

C# 我的代码没有做数学运算..它只是将数字粘在一起

我正在创建一个友好的人工智能,其名字是菲尔;),但我需要它能够做数学。我确实尝试过,也尝试过+=,但它不起作用。例如,如果我执行 1+1,而不是 2,则结果为 11。这是我的代码:

namespace Game
{
    public static class Program
    {

        //commands
        public static string enteredCommand;
        public static string commanddomath = "doMath";

        //Math command stuff
        public static string MathOperation;
        public static string FirstOperatorNumber;
        public static string SecondOperatorNumber;
        public static string FinalAwnser;

        static void Main()
        {
           if (enteredCommand == "doMath")
           {
            Console.WriteLine("Ok");
            Console.WriteLine("What Operation should I do?");
            MathOperation = Console.ReadLine();
            if (MathOperation == "+")
            {
                Console.WriteLine("Addition! Easy! What is the first number? ex. 6");
                FirstOperatorNumber = Console.ReadLine();
                Console.WriteLine("Ok, …
Run Code Online (Sandbox Code Playgroud)

c# console

-4
推荐指数
1
解决办法
143
查看次数

标签 统计

c# ×1

console ×1