我需要帮助.有人可以帮我一下,告诉我这不起作用吗?感谢您的帮助. [英] I need help. Can someone help me out and tell me what I this is not working? Thank you for the help.

查看:92
本文介绍了我需要帮助.有人可以帮我一下,告诉我这不起作用吗?感谢您的帮助.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
            string diverName;
            string city;
            double score;
            double total_score;
            double final_score = 0;
            double difficulty;
            double highest;
            double lowest;
            double overall;
            sbyte process_diver;
            int judge_ctr;
            int num_divers = 0;

            Console.Write("Report to the media\n");
            Console.Write("Event: Diving competition\n\n");

            do
            {
                Console.Write("{0:F2}", "Enter the diver's name: ");
                Console.WriteLine("diverName");

                Console.Write("{0:F2}", "Enter the diver's city: ");
                Console.WriteLine("city");

                highest = -1;
                lowest = 11;
                total_score = 0;
                judge_ctr = 1;
                do
                {
                    Console.Write("{0:F2}", "Enter the score given by judge #");
                    Console.Write("{0:F2}", judge_ctr);
                    Console.Write("{0:F2}", ": ");
                    score = Convert.ToInt32(Console.ReadLine());

                    if (score <= 0 || score >= 11)
                    {
                        Console.Write("{0:F2}", "Values must be between 0 and 10.");
                        Console.Write("{0:F2}", "Enter the score given by judge # ");
                        Console.Write("{0:F2}", judge_ctr);
                        Console.Write("{0:F2}", ": ");
                        score = Convert.ToInt32(Console.ReadLine());
                    }

                    total_score += score;
                    judge_ctr++;

                }
                while (judge_ctr <= 5);

                Console.Write("{0:F2}", "Enter between 1.0 and 1.67 inclusive.");
                Console.Write("{0:F2}", "\n");
                Console.Write("{0:F2}", "What was the degree of difficulty? ");
                score = Convert.ToInt32(Console.ReadLine());

                if (difficulty <= (0.9) || difficulty >= (1.68)) ;
                {
                    Console.Write("{0:F2}", "Invalid range. Choose between 1.0 and 1.67");
                    Console.Write("{0:F2}", "What was the degree of difficulty? ");
                    score = Convert.ToInt32(Console.ReadLine());
                }

                score = (total_score - lowest - highest) / 3 * difficulty;

                Console.Write("{0:F2}", "Diver: ");
                Console.Write("{0:F2}", diverName);
                Console.Write("{0:F2}", ", City: ");
                Console.Write("{0:F2}", city);
                Console.Write("{0:F2}", "\n");
                final_score = final_score + overall;
                num_divers = num_divers + 1;
                Console.Write("{0:F2}", "Overall  score was ");
                Console.Write("{0:F2}", final_score);
                Console.Write("{0:F2}", ".");
                Console.Write("{0:F2}", "\n");
                Console.Write("{0:F2}", "\nDo you want to process another diver (Y/N)? ");
                score = Convert.ToInt32(Console.ReadLine());
                process_diver = sbyte.Parse("process_diver");

                Console.WriteLine("50\n'");

            }
            while (process_diver == 'Y' || process_diver == 'y');

            Console.Write("{0:F2}", "EVENT SUMMARY\n");
            Console.Write("{0:F2}", "Number of divers participating: ");
            Console.Write("{0:F2}", num_divers);
            Console.Write("{0:F2}", "\n");
            Console.Write("{0:F2}", "Average score of all divers: ");
            Console.Write("{0:F2}", final_score / num_divers);
            Console.Write("{0:F2}", "\n");

            Console.WriteLine("\n\nPress any key to continue...");
            Console.ReadLine();

推荐答案

警告1可能错误的空语句72 66 Lab3A


错误2使用未分配的局部变量``difficulty''72 21 Lab3A


错误3使用未分配的局部变量"diverName"
82 41 Lab3A

错误4使用未分配的局部变量"city"
84 41 Lab3A


错误5使用未分配的局部变量"overall"
86 45 Lab3A

这只是我在C#中的第三周.而且我不是专业人士.这就是它现在告诉我的一切都是错误的.希望发生的事是我下课后有人帮助我.他告诉我以为我还不知道.然后在那之后他忘记了我在C#中谈论C ++.这就是我走了多远.到目前为止,感谢您提供的所有帮助.我希望这会有所帮助.
Warning 1 Possible mistaken empty statement 72 66 Lab3A


Error 2 Use of unassigned local variable ''difficulty'' 72 21 Lab3A


Error 3 Use of unassigned local variable ''diverName''
82 41 Lab3A

Error 4 Use of unassigned local variable ''city''
84 41 Lab3A


Error 5 Use of unassigned local variable ''overall''
86 45 Lab3A

This is only my 3rd week in C#. And I''m not a pro. This is everything it is telling me right now that is wrong. Want happen was I had someone help me after class. And he was telling me thinks I didn''t know yet. Then after that he forgot I was in C# and was talking about C++. So this is how far I got. Thanks so far for all the help. I hope this will help.


您有很多Console.Write()语句实际上没有任何意义,包括一些带有冗余格式字段的语句.回到您的笔记,考虑一下代码中这些点要达到的目标.如果您试图从用户那里获取一些信息,那么您可能需要某种形式的Read而不是Write.
You have lots of Console.Write() statements that really don''t make any sense, including some with redundant formatting fields. Go back to your notes and think about what you are trying to achieve at those points in the code. If you are trying to get some information from the user then you probably need some form of Read rather than a Write.


马特


听起来您可能想先跑步再走路.所以慢慢来. . .我不太确定您现在处于什么阶段,所以从头开始(如果前两点或三点太基本了,请道歉).

1.我想您已经在某些版本的Visual Studio中创建了C#Windows控制台应用程序

2.您有一个Hello World应用程序可以工作吗?如果没有,请参见:
http://msdn.microsoft.com/en-us/library/k1sx6ed2 (v = vs.71).aspx [
Matt


Sounds like you might be trying to run before you can walk. So take this slowly . . . I''m not quite sure what stage you''re at, so start at the beginning (with apologies if the first 2 or 3 points are too basic).

1. I presume you''ve created a C# Windows Console application in some version of Visual Studio

2. Have you got a Hello World application to work? If not, see:
http://msdn.microsoft.com/en-us/library/k1sx6ed2(v=vs.71).aspx[^]
and get the up and running.

3. Now start replacing the

System.Console.WriteLine("Hello World!");



大括号之间的线



line between the braces

{
}


与您的代码.

建议您一次添加一行或几行.
在每个阶段,对其进行编译,排除所有问题,测试其是否达到预期的效果,在继续进行之前对其进行调试.

确保您完全了解每一行的内容-甚至每个字符-计算机都有按照其所告诉的内容进行操作的令人愉悦的/令人讨厌的习惯-按字母顺序-既不多也少-即使事半功倍,即使是最好的也能抓住一切,是微不足道的错误.

4.请参阅Richard MacCutchan的解决方案
你有类似的东西:


with your code.

Suggest you do this adding one / a few lines at a time.
At each stage, compile it, sort out any problems, test that it does what you expect, debug it before moving on.

Make sure you understand EXACTLY what every single line does - even every character - computers have the delightful / infuriating habit of doing exactly what they are told - to the letter - neither more nor less - even the best can get caught by what, with hindsight, are trivial errors.

4. See Richard MacCutchan''s solution
You have things like:

Console.WriteLine("diverName");


但是从用户的任何输入中都没有要读取的内容.如果您不告诉计算机读取某些输入,则不会.

5.查看您的编译器错误-可能错误的空语句


but then nothing to Read in any input from the user. If you don''t tell the computer to read some input, it won''t.

5. Looking at your compiler errors - possible mistaken empty statement

if (difficulty <= (0.9) || difficulty >= (1.68)) ;


最后的分号是错误的. 如果"括号中包含单个语句或语句块


The semicolon at the end is wrong. ''if'' either has a single statement or a block of statements in braces

if(condition) statement;





if(condition)
{
statements
}



6.使用未分配的局部变量"difficulty"(和其他类似的变量)

与上述相同的行-在为变量赋值之前,请使用名为"difficulty"的变量.您已经在顶部附近声明了它-但是在为它赋值之前,您无法有意义地使用它.请参阅上面的第4点-我认为您的意思是从控制台读取一个值.

请记住-那些编译器错误可以为您提供帮助-它们通常不是完全用简单的英语表达的,但是(通常)可以通过一些思考和努力来解决.他们应该给您提供引起问题的行号(有时可能会混淆以下几行),并经常给您提供该行上的字符. Visual Studio往往非常擅长帮助您在代码中找到问题点(双击错误消息!).要获得更多帮助,您还可以单击错误消息,然后按F1键以获取有关该特定错误的上下文帮助-这可以解释问题所在.失败的话,Google搜索错误消息可能会很有启发性.

如果毕竟遇到了真正让您感到困惑的错误,请在此处用代码,错误和导致错误的哪一行的详细信息发布问题.

祝你好运!



6. Use of unassigned local variable ''difficulty'' (and others similarly)

Same line as above - you are using the variable called ''difficulty'' before you''ve assigned a value to it. You''ve declared it near the top - but until you assign some value to it you can''t meaningfully use it. See my point 4. above - I think you mean to Read a value into it from the Console.

Remember - those compiler errors are there to help you - they often aren''t exactly in plain English, but can (usually) be worked out with a bit of thought and effort. They should give you the line number that''s causing the problem (or sometimes the following line which can be confusing) and often the character on the line. Visual Studio tends to be very good at helping you locate the problem point in your code (double-click the error message!). For more help you can also click the error message and then press F1 to get context help on that specific error - which may explain what the problem is. failing that, Googling the error message can be enlightening.

If after all that you hit an error that really has you stumped, post a question here, with the code, the error and details of which line is causing the error.

Best of luck!


这篇关于我需要帮助.有人可以帮我一下,告诉我这不起作用吗?感谢您的帮助.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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