未正确检查某些预设响应。
请不要给出答案,只是希望得到一些关于如何改进的指导。
预置响应:"hai!“应该赢得“哦,”,“计算机”应该赢得“科学”。
下面是我的计算核心函数的代码;
int compute_score(string word)
{
int j = strlen(word);
int total = 0;
int index;
for (int i = 0; i < j; i++)
{
char c = word[i];
if (isupper(c))
{
c = c - 65;
index = c;
total = POINTS[index];
}
if (islower(c))
{
c = c - 97;
index = c;
total = POINTS[index];
}
}
发布于 2021-05-18 10:21:04
假设您正在尝试对字符分值求和。
这一行在每次迭代时将total
变量重新赋值为最新的奇异点值:
total = POINTS[index];
如果在for
循环之后查看一下total
的值,就会发现它是字符串中最后一个有效字符的值。
取而代之的是,使用plus-equals运算符来添加以下内容:
total += POINTS[index];
别忘了从那个函数中返回一些东西。
https://stackoverflow.com/questions/67579059
复制相似问题