为什么我的代码忽略了它自身的很大一部分?

发布于 2025-01-10 16:37:48 字数 1469 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2025-01-17 16:37:49

因为类型不匹配!
您将“diff”定义为字符并在 switch 语句中使用它。但是,在第二个 switch 语句中,您删除了引号并将其用作数字。这会导致根据 ascii 表进行 char 到 int 的转换。

ASCII 表

看一下十进制字段,作为 int 的数字 1 对应于现实生活中很少见到的不可打印字符。字符“1”对应49。

解:

switch(diff){
case '1':   //notice the quotations
   //rest of code
   break;
}

Because of type mismatch!
you defined "diff" as a char and use it as such in your switch statement. However, in your second switch statement, you remove the quotes and use it as a number. That causes a char to int conversion according to the ascii table.

ASCII Table

Look at the decimal field, the number 1 as an int corresponds to a non-printable character that you will rarely see in real life. The character '1' corresponds to 49.

Solution:

switch(diff){
case '1':   //notice the quotations
   //rest of code
   break;
}
故事还在继续 2025-01-17 16:37:49

对于这一行,

if (diff != 1 && diff != 2 && diff != 3 && diff != 4) { goto start; }

您的意思是

if (diff != '1' && diff != '2' && diff != '3' && diff != '4') { goto start; }

考虑到 diff 是键入的 char 而不是 int

for this line

if (diff != 1 && diff != 2 && diff != 3 && diff != 4) { goto start; }

you mean

if (diff != '1' && diff != '2' && diff != '3' && diff != '4') { goto start; }

given that diff is a typed in char not an int

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文