1

这是一个家庭作业问题,但我只是寻求调试帮助。我不确定是什么导致了这些错误。

int CalculateResult(int High, int Low)
{
  int Result;
  int count = 0;
  int check;
do
    {
    printf("Enter the value to check within the range: ");
    scanf("%d",&Result);

     if (Result == 0)
     {
     printf("Error! Positive value only!\n");
     }

     else if (Result < -1)
     {
     printf("Error! Positive value only!\n");
     }

     else if (Result>= 1);
     {
     for (check = Low ; check <= High;check++)
         {
         if (check%Result==0)
            {
            (count++);
            }
         }
     } 
    while (Result != -1);
    return (count);
    }
}

我有两个错误:174:1 --- 预期在 } 标记之前,然后有 174:1 --- 预期在输入结束时声明

有人看到有什么问题吗?对不起,它很乱,我是菜鸟。

4

4 回答 4

1

Change

     } 
    while (Result != -1);
    return (count);
    }
}

to

     } 
     }
    while (Result != -1);
    return (count);
}
于 2013-03-04T22:36:23.293 回答
1

If you indent your code correctly, you can easily see where the error is:

int CalculateResult(int High, int Low)
{
  int Result;
  int count = 0;
  int check;
  do
  {
     printf("Enter the value to check within the range: ");
     scanf("%d",&Result);

     if (Result == 0)
     {
         printf("Error! Positive value only!\n");
     }

     else if (Result < -1)
     {
         printf("Error! Positive value only!\n");
     }

     else if (Result >= 1);
     {
        for (check = Low ; check <= High; check++)
        {
           if (check%Result == 0)
           {
                 (count++);  <-------- The () are OK, but not necessary.
           }
        }
     }
  }  <---------------------------  Moved this brace up from below.
  while (Result != -1);

  return (count);
}  
于 2013-03-04T22:36:43.290 回答
1

在 while 指令之前添加“}”。你失去了一个括号:) 现在,“while”是最后一个“else if”指令。正确的架构: do {
//Some code here
} while (clause);

于 2013-03-04T22:32:42.080 回答
0

只想说两件事:
1. 检查是否有所有需要的括号
2. 检查是否缺少“;” 或者如果有一个“;” 它不应该在哪里
这是一个家庭作业问题所以我不会直接给你答案
好吧:),还有一些提示:
1.总是缩进你的代码
2.一个ifelse if没有一个块来做任何事情可能是无用的ifelse if;)

于 2013-03-04T22:39:38.480 回答