有人能告诉我,我做了什么,我应该改变什么是错的?我是初学者(C#) [英] Can someone tell me whats wrong with what I have done, and what I should change? I am a beginner (C#)

查看:85
本文介绍了有人能告诉我,我做了什么,我应该改变什么是错的?我是初学者(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我下面做的事情中,一切都很好,但是:

Console.WriteLine(你还是个孩子);

(以及所有其他类似的对此^)说分号后有错误



In the stuff I did below, everything is fine but:
Console.WriteLine("You are a child");
(and all the other ones similar to this^) say there is an error after the semicolon

namespace B13
{
    class Program
    {
        static void Main(string[] args)
        {
            int age = 1;
            while (age >= 50)

            {
                Console.WriteLine("Enter your age");


                age = Convert.ToInt32(Console.ReadLine());
                {

                    if (age > 29)
                    {
                        do


                            Console.WriteLine("You are old!");
                    }
                    else
                    {
                        if (age == 19)
                            while (age != 30)
                                do
                                    Console.WriteLine("You are getting old");




                     else
                        {
                            if (age == 13)
                                while (age != 19)
                                    do
                                        Console.WriteLine("You are a teenager");


                       else
                            {
                                if (age < 13)

                                    do
                                        Console.WriteLine("You are a child");
                    }
                            Console.WriteLine(age);
                            Console.ReadKey();


                        }
                    }
                }
            }
        }
    }
}





我尝试了什么:



我尝试删除分号,但我不认为那是我应该做的,我对此很新,而且很困惑。有人请求帮助我理解我做错了什么。谢谢



What I have tried:

I tried removing the semicolon, but i don't think that is what I am supposed to do, I am very new to this, and very confused. Can someone pleaasee help me understand what I did wrong. Thank You

推荐答案

以下内容将进行编译,但代码存在语义问题:

如果您输入19岁或13岁,它将会永远循环。输入14,15,16,17,18将不打印任何内容。我不认为你想用。可能你想要像

if(age> = 14和age< = 19)Console.WriteLine(你是青少年);





The following will compile, but the code has semantic issues:
If you enter age of 19, or 13 it will loop forever. Inputs 14,15,16,17,18 will print nothing. I don't think you want to use while. Probably you want something like
if (age >=14 and age <= 19) Console.WriteLine("You are a teenager");


using System;

namespace B13
{
    class Program
    {
        static void Main(string[] args)
        {
            int age = 1;
            while (age >= 50)

            {
                Console.WriteLine("Enter your age");

                age = Convert.ToInt32(Console.ReadLine());
                {
                    if (age > 29)
                    {
                        Console.WriteLine("You are old!");
                    }
                    else
                    {
                        if (age == 19) while (age != 30) Console.WriteLine("You are getting old");

                        else
                        {
                            if (age == 13) while (age != 19) Console.WriteLine("You are a teenager");

                            else
                            {
                                if (age < 13) Console.WriteLine("You are a child");
                            }
                            Console.WriteLine(age);
                            Console.ReadKey();
                        }
                    }
                }
            }
        }
    }
}


什么应该是所有那些,而分散在各处?

那些不是随机的陈述!



你的代码非常混乱,你应该告诉我们你的代码应该是什么。
What are supposed to be all those while and do scattered everywhere?
Those are not random statements!

Your code is very confuse, you should tell us what is supposed to do your code.


这篇关于有人能告诉我,我做了什么,我应该改变什么是错的?我是初学者(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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