我的错误代码:CS1513 C#}预期。当我这样做时,我得到另一堆错误 [英] My error code: CS1513 C# } expected. When I do this I get another bunch of errors

查看:89
本文介绍了我的错误代码:CS1513 C#}预期。当我这样做时,我得到另一堆错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的错误代码:CS1513 C#}预期。当我这样做时,我得到另一堆错误。

所以继承我的代码,





My error code: CS1513 C# } expected. When I do this I get another bunch of errors.
So heres my code,


using System;
using System.Diagnostics;

namespace Next

{

    class MainClass

    {

        public static void Main(string[] args) // this is a method called "Main". It is called when the program starts.

        {
            Random numberGenerator = new Random();
            int num01 = numberGenerator.Next(1, 21);
            int num02 = numberGenerator.Next(1, 21);
            int num001 = 1;
            int num002 = 2;
            int num003 = 3;
            int num004 = 4;
            int num005 = 5;

            Console.WriteLine("                                                  Welcome to XMATH!");
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("                                                  Difficulty Selection \n1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9");
            Console.WriteLine("To START the first level press 1 \nTo ENTER a code press 2\nTo EXIT the game press 3 \nTo see the RANKLIST press 4 \nTo see the CREDITS press 5");
            Console.WriteLine();
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");


            int answer01 = Convert.ToInt32(Console.ReadLine());
            if (num001 == answer01)
            {
                Console.WriteLine();
                Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
                Console.WriteLine();
                Console.Write("What is " + num01 + " plus " + num02 + "?: ");
                int answer = Convert.ToInt32(Console.ReadLine());
                if (answer == num01 + num02)
                {

                    Console.WriteLine("Well done! Your answer is correct.");

                }
                else
                {

                    Console.WriteLine("Are you even trying?");

                }
            }


            int answer02 = Convert.ToInt32(Console.ReadLine());
            else if (num002 == answer02)
            {
                Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
                Console.WriteLine("                                                  Still in progress. \n                                                  Please wait for updates");
                Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
            }
            Console.ReadKey();
            Console.WriteLine();
        }

    }

}





感谢您的帮助



我尝试过:



我已经添加了大括号,但是我得到了另一堆错误。



Thanks for any helping hand

What I have tried:

I already added the curly bracket but than I get another bunch of errors.

推荐答案

你在if / else if结构的中间声明了一个变量。



int answer02 = Convert.ToInt32(Console.ReadLine());在错误的地方。



You are declaring a variable in the middle of the if/else if structure.

int answer02 = Convert.ToInt32(Console.ReadLine()); is in the wrong spot.

if (){

}
// you cannot put code here.
else if ()
{

}


问题是你的否则在你的 answer02之后的语句声明。 else if语句总是必须立即遵循 if 语句,这不是这里的情况,因为answer02声明介于两者之间。



你可以做两件事来修复错误,你必须看看哪一个匹配你想要对你的应用程序做什么。第一种方法是用if替换else if。另一种方法是将int answer02 = ...语句放在第一个if语句之前。这两个应用程序都将编译,但它们的工作方式会有所不同。决定你想要哪一个。
The problem is your else if statement after your answer02 declaration. An else if statement always has to follow an if statement immediately, which is not the case here because the answer02 declaration is in between.

There are two things that you can do to fix the error, and you'll have to see which one matches the best what you want to do with your application. The first way would be to replace the "else if" with simply "if". The other way would be to put the "int answer02 = ..." statement before your first if statement. Both applications will compile, but their workings will be different. Decide which one you want.


你有一个否则如果没有紧接在前的如果(紧接在 int answer02 = ... 声明之后)。删除 else
You have an else if without an immediately preceding if (immediately after the int answer02 = ... declaration). Remove that else.


这篇关于我的错误代码:CS1513 C#}预期。当我这样做时,我得到另一堆错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆