我13岁,刚接触编码。它会显示一条错误消息,说'}预期'请帮助!!! [英] I'm 13 and new to coding. It shows up with an error message saying '}expected' Please help!!!

查看:69
本文介绍了我13岁,刚接触编码。它会显示一条错误消息,说'}预期'请帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.Write("what is your name?");
			string name = Console.ReadLine();
			Console.WriteLine("what is your age?");
			try
			{
				int age = Convert.ToInt32(Console.ReadLine());
				if (age == 13)
				{
					Console.WriteLine("I am " + age.ToString() + " too!");
					Console.WriteLine("how are you?");
					string mood = Convert.ToString(Console.ReadLine());
					Console.WriteLine("So you're" + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n <yes or="">");
					string yesno = Console.ReadLine();
					if (yesno.ToLower() == "yes")
					{
						Console.WriteLine("Cool...");
						Console.WriteLine("let's do some maths.");
						Random numberGenerator = new Random();
						int num01 = numberGenerator.Next(1, 11);
						int num02 = numberGenerator.Next(1, 11);
						Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
						int answer = Convert.ToInt32(Console.ReadLine());
						if (answer == num01 * num02)
						{
							Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadKey();
							Console.WriteLine("Lets so some more...");

							Random numberGenerator1 = new Random();
							int num03 = numberGenerator1.Next(11, 31);
							int num04 = numberGenerator1.Next(11, 31);
							Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
							int answer1 = Convert.ToInt32(Console.ReadLine());
							if (answer1 == num03 * num04)
							{
								Console.WriteLine("Well done you know what " + num03 + " times " + num04 + " is! Congrats");
								Console.WriteLine("<press the="" anykey="" to="" continue="">");
								Console.ReadKey();
								Console.WriteLine("Lets so some more...");
						}
						else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadLine();
								Random numberGenerator2 = new Random();
								int num05 = numberGenerator1.Next(11, 31);
								int num06 = numberGenerator1.Next(11, 31);
								Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
								int answer2 = Convert.ToInt32(Console.ReadLine());
								if (answer2 == num05 * num06)
								{
									Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
									Console.WriteLine("<press the="" anykey="" to="" continue="">");
									Console.ReadKey();
									Console.WriteLine("Lets so some more...");
						}
					}
					else
					{

						Console.WriteLine("You lied to me...");
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
				}
				else
				{
					Console.WriteLine("I am 13");
					Console.WriteLine("how are you?");
					string mood = Convert.ToString(Console.ReadLine());
					Console.WriteLine("So you're " + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n <yes or="">");
					string yesno = Convert.ToString(Console.ReadLine());
					if (yesno.ToLower() == "yes")
					{
						Console.WriteLine("Cool...");
						Console.WriteLine("let's do some maths.");
						Random numberGenerator = new Random();
						int num01 = numberGenerator.Next(1,11);
						int num02 = numberGenerator.Next(1, 11);
						Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
						int answer = Convert.ToInt32(Console.ReadLine());
						if (answer == num01 * num02)
						{
							Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
						}
						else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" any="" key="" to="" exit.="">");
							Console.ReadLine();
						}
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
					else
					{

						Console.WriteLine("You lied to me...");
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
				}
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine("You should have entered a number - go back to school...");		
				Console.WriteLine("<press the="" any="" key="" to="" exit="">");
				Console.ReadKey();
			}
		}
	}
}

推荐答案

真的很简单。你在某处错配了 {} 。虽然,在你发布代码的方式中,任何人都不可能分辨出来,因为它没有正确格式化。



编辑

------------------------------

现在格式正确,你的两个如果语句缺少关闭} 字符。



此外,为了便于调试并更容易遵循此代码,请在与用户对话的每一步将此代码分解为多个方法。
It's simple enough really. You have mismatched { and } somewhere. Though, in the way you posted your code, it's pretty much impossible for anyone to tell where because it's not formatted properly.

EDIT
------------------------------
Now that it is formatted properly, two of your if statements are missing closing } characters.

Also, to make debugging and following this code easier, break this code out into multiple methods at each step in your "conversation" with the user.


if (answer2 == num05 * num06)

下面似乎缺少了closng大括号。



below seems to be missing closng brace.

else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadLine();
								Random numberGenerator2 = new Random();
								int num05 = numberGenerator1.Next(11, 31);
								int num06 = numberGenerator1.Next(11, 31);
								Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
								int answer2 = Convert.ToInt32(Console.ReadLine());
								if (answer2 == num05 * num06)
								{
									Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
									Console.WriteLine("<press the="" anykey="" to="" continue="">");
									Console.ReadKey();
									Console.WriteLine("Lets so some more...");
						}
					}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("what is your name?");
            string name = Console.ReadLine();
            Console.WriteLine("what is your age?");
            try
            {
                int age = Convert.ToInt32(Console.ReadLine());
                if (age == 13)
                {
                    Console.WriteLine("I am " + age.ToString() + " too!");
                    Console.WriteLine("how are you?");
                    string mood = Convert.ToString(Console.ReadLine());
                    Console.WriteLine("So you're" + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n ");
                    string yesno = Console.ReadLine();
                    if (yesno.ToLower() == "yes")
                    {
                        Console.WriteLine("Cool...");
                        Console.WriteLine("let's do some maths.");
                        Random numberGenerator = new Random();
                        int num01 = numberGenerator.Next(1, 11);
                        int num02 = numberGenerator.Next(1, 11);
                        Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
                        int answer = Convert.ToInt32(Console.ReadLine());
                        if (answer == num01 * num02)
                        {
                            Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
                            Console.WriteLine("");
                            Console.ReadKey();
                            Console.WriteLine("Lets so some more...");
                            Random numberGenerator1 = new Random();
                            int num03 = numberGenerator1.Next(11, 31);
                            int num04 = numberGenerator1.Next(11, 31);
                            Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
                            int answer1 = Convert.ToInt32(Console.ReadLine());
                            if (answer1 == num03 * num04)
                            {
                                Console.WriteLine("Well done you know what " + num03 + " times " + num04 + " is! Congrats");
                                Console.WriteLine(""); Console.ReadKey(); Console.WriteLine("Lets so some more...");
                            }
                            else
                            {
                                Console.WriteLine("Go gack to school");
                                Console.WriteLine(""); Console.ReadLine();
                                Random numberGenerator2 = new Random();
                                int num05 = numberGenerator1.Next(11, 31);
                                int num06 = numberGenerator1.Next(11, 31);
                                Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
                                int answer2 = Convert.ToInt32(Console.ReadLine());
                                if (answer2 == num05 * num06)
                                {
                                    Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
                                    Console.WriteLine(""); Console.ReadKey(); Console.WriteLine("Lets so some more...");
                                }
                                else
                                {
                                    Console.WriteLine("You lied to me...");
                                    Console.WriteLine("");
                                    Console.ReadKey();
                                }
                            }

                        }
                        else
                        {
                            Console.WriteLine("I am 13");
                            Console.WriteLine("how are you?");
                            string mood1= Convert.ToString(Console.ReadLine());
                            Console.WriteLine("So you're " + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n ");
                            string yesno1 = Convert.ToString(Console.ReadLine());
                            if (yesno1.ToLower() == "yes")
                            {
                                Console.WriteLine("Cool...");
                                Console.WriteLine("let's do some maths."); Random numberGenerator1 = new Random(); int num011 = numberGenerator1.Next(1, 11); int num021 = numberGenerator1.Next(1, 11);
                                Console.WriteLine("What is " + num01 + " times " + num021 + " ?");
                                int answer1 = Convert.ToInt32(Console.ReadLine());
                                if (answer1 == num01 * num021)
                                {
                                    Console.WriteLine("Well done you know what " + num01 + " times " + num021 + " is! Congrats");
                                }
                                else
                                {
                                    Console.WriteLine("Go gack to school"); Console.WriteLine(""); Console.ReadLine();
                                }
                                Console.WriteLine(""); Console.ReadKey();
                            }
                            else
                            {
                                Console.WriteLine("You lied to me...");
                                Console.WriteLine("");
                                Console.ReadKey();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("You should have entered a number - go back to school...");
                Console.WriteLine("");
                Console.ReadKey();
            }
        }
    }
}


这篇关于我13岁,刚接触编码。它会显示一条错误消息,说'}预期'请帮助!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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