#ST# HW1 for ST

#Briefly describe an error from your past projects that you have recently completed or an error from other projects which impress you most. State the reason, impact of the error and how did you find it.

 

Answer:

Look at the code below, it was written by myself when I just began to learn c++.

int sum(int start, int end){

  int total = 0;

  for(int i = start; i <= end; ++i){

    total += i;

  }

  return total;

}

  I always got the wrong number and  it troubled me a lot. As we know, the computers are obedient, they obey the program for better or worse. Thus, the wrong result was caused by my bad program. 

  How I solved it? I listed two numbers and computed the result as the code told, then I found the reason, because of the "++i", it always ignored the first number. I corrected it as "i++", then I got the right result. 

  It was my first time to correct the program and get the right result by myself, it was pretty fulfilling so I can still remember it. We should be patient and careful to create our program.

posted @ 2017-02-26 20:43  WangXiaojianTju  阅读(135)  评论(0编辑  收藏  举报