诚实的学习者问题 [英] honest learner question

查看:78
本文介绍了诚实的学习者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要练习的代码试图有效地调试代码.它有几个错误,是故意这样做的,但是我正在尝试通过查看错误和警告列表中的错误类型来学习编程的技巧.我将发布代码,然后显示错误,并且大家都将指导我调试该程序.

the code i am about to an exercise i am using in trying to be effective to debug a code. it has several errors and deliberately do but i am trying to learn the art of programming by looking at the types of error in the error and warning list. i will post the code , then the errors and you all guide me in debugging this program.

#include <iostream.h>
#include <conio.h>

int min(int* &a, int b);

void main()

{
int* x;
int i=0;

 x = new float [0];

 cout<<"\n Enter whole numbers, enter any letter when finishd.";

 while


    cin>>x[i];

   {i++};

   cout<<"Enter smallest number is:<<min(x,i)";

   getch();

   return 0;:

   }

   int main (int*&a , int b);

   {int m = a[0];

   for (int i = 1; i<b; i++)
   {
      if (a[i]<m)
      {m=a(i);}
      }
      return m;}





line cpp 12,5 cannot convert ''float*'' to  ''int''
line cpp 18,1 while statement missing (
line cpp 20,9 statement missing;
line cpp 20,13 ''main()''cannot return a value
line cpp 26,14 unreachable code -warning
line cpp 26,14 expression syntax
line cpp 28,5 statement missing
line cpp 32,15 undefined symbol ''a''
line cpp 34,24 undefined symbol ''b''
line cpp 39,16 ''main()cannot return a value.
line cpp 39,1 compound statement missing }
line cpp 40,1compound statement missing
x is assigned a value that is never used


现在!!!如何使用这些警告来调试程序?


Now!!! how do i use these warnings to debug my program?
what does the second number contained where the error shows up but 12,5 why the , between 12 and 5 and what does the 5 represents?

推荐答案

hi ..

12表示行,5表示列,请参见您的代码,从
开始
hi..

12 means line and 5 means columns, see in your code starting from
#include <iostream.h>

计数12行(向下),您将看到

count 12 line(downward) you will see

x= new float [0];



x为int并使用float实例化时,显然会导致错误..

希望在您的代码中找到其余的错误,...进行调试吧:)

希望对您有帮助...

如果有帮助,别忘了投票


谢谢



where x is int and you instantiate with float, obviously it cause an error..

hope find the rest of errors in your code,... enjoy the debugging :)

hope it helps...

don''t forget to vote if it helps you


thanks


不要!
您正在混淆不同的概念和问题.

首先:您发布的代码包含错误而不是错误(有一个细微的区别:错误是违反语言语法的东西,它使您的代码无法翻译成机器代码. bug 是不违反语言规则的逻辑错误":只需告诉机器做与您想像不同的事情即可.
实际上,您无法调试它,因为您还没有要调试的东西.

第二:不要考虑较长的错误序列:错误会使解析器对下一个文本序列的含义感到迷惑.一次更正错误并重新编译,然后查看错误列表的变化.

第三:如果我们不知道该代码的用途,就无法修复该代码.
例如:您有一个
分配为
Don''t!
You are mixing up different concept and issues.

First: the code you post contains ERRORS not BUGS (there is a subtle difference: an error is something the violates the language syntax, that makes your code not translatable into machine code. A bug is a "logical mistake" that doesn''t violate the language rules: simply you tell the machine to do something different than what you think).
Actually you cannot debug it because you have nothing (yet) to debug.

Second: don''t consider long error sequences: an error can make the parser to be fooled about the meaning of the next text sequence. Correct the errors one at time and recompile, and see how the error list changes.

Third: We cannot fix a code if we don''t know what that code is intended to do.
For example: you have an
int* x;

x = new float [0];


除了float[0]的废话外,您还尝试将int 分配为float.这是不一致的,但是更正是什么?全部更改为int或全部更改为浮点数?这取决于您要做什么.

四:你有


Apart the nonsense of float[0], you are trying to treat as int what is allocated as float. This is incongruent, but what is the correction? change all to int, or all to float? It depends on what you want to do.

Four: you have

while cin>>x[i] 

.
while的正确语法是

.
The correct syntax for while is

while(condition) statement


缺少()使编译器解析器无法解释下一条语句的解释方式.因此,以下错误不准确.

您应该一个一个地纠正,然后重新编译,直到所有语法都已调整.
到那时,您有一个可以执行的程序,并且-可能-行为不符合您的期望.
那时,您必须对其进行调试,以查看实际上在执行语句和分配变量时发生了什么.

现在,您可以对问题进行简要说明,然后再编辑问题吗?


The missing () makes the compiler parser to loose about how the next statement should be interpreted. hence the following errors are not accurate.

You should correct one by one and recompile until all the syntax had been adjusted.
At that point you have a program that can be executed, and -probably- don''t behave as you want to.
At that time you must debug it to see what, in fact, goes on while statements are executed and variables assigned.

Now, can you edit the question, perpending a brief explanation on what you want that code to do?


这篇关于诚实的学习者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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