如何让我的代码说 "You can't divide to 0"
How do I make my code say "You can't divide to 0"
所以,我一直在练习函数循环等,我坚持这样做 this.I 我是编程的新手,但我进行了很多搜索,这让我学得更快。
(顺便说一句,我尝试了我的代码来检查用户的输入是否是数字。)
printf("Define numbers.\n");
printf("Select: ");
scanf("%d", &x);
printf("Select: ");
scanf("%d", &y);
if (y = temp)
{
printf("Division of something by 0 is undefined.\n");
}
else
{
printf("Division of %d and %d is %d\n", x, y, div(x, y));
}
所以我声明了 temp = 0 我认为它可以解决问题,但它没有。
当您执行 y = temp
时,您为 y 提供了临时值,在本例中为 0。在 c 中,转换为 false
逻辑值
你想做的是
if (y == temp)
==
运算符测试两个变量之间的相等性
所以,我一直在练习函数循环等,我坚持这样做 this.I 我是编程的新手,但我进行了很多搜索,这让我学得更快。 (顺便说一句,我尝试了我的代码来检查用户的输入是否是数字。)
printf("Define numbers.\n");
printf("Select: ");
scanf("%d", &x);
printf("Select: ");
scanf("%d", &y);
if (y = temp)
{
printf("Division of something by 0 is undefined.\n");
}
else
{
printf("Division of %d and %d is %d\n", x, y, div(x, y));
}
所以我声明了 temp = 0 我认为它可以解决问题,但它没有。
当您执行 y = temp
时,您为 y 提供了临时值,在本例中为 0。在 c 中,转换为 false
逻辑值
你想做的是
if (y == temp)
==
运算符测试两个变量之间的相等性