【发布时间】:2021-12-19 05:56:15
【问题描述】:
#include <stdio.h>
int main (void) //starting entry of integer indicate not associated with any data types argument
{
int value1, value2, calculate = 0; //integer values
printf ("\nProgram should perform the following:");
printf("\n");
printf ("\nHave the user enter two different integer numbers to be divided by the program ");
{
printf ("\nIf the division of both numbers");
printf("\n");
printf ("\nresult with the remainder of zero,");
printf("\n");
printf ("\nby the second number.");
printf("\n");
printf ("Example: thirty-five divided by seven will have a remainder of zero");
printf ("\n");
}
printf ("Please enter the first integer number>>");
scanf ("%i", &value1);
printf ("Please enter the second integer>> ");
scanf ("%i", &value2);
if (value1 % value2 == 0 ) {
printf ("\n%i is evenly divisible by %i\n", value1, value2);
calculate = value1 / value2;
printf ("%i / %i = %i\n", value1, value2, calculate);
else
printf ("\n%i is not evenly divisible by %i\n", value1, value2);
return 0;
}
我编写的这段代码工作正常。但是我似乎找不到使用哪个 else 或 else if 语句来使代码显示错误:如果用户输入的第二个数字为零,则程序中允许为零。
【问题讨论】:
-
这不是C#,请去掉C#标签。另外,您能否改进代码格式(提示:使用编辑器中的
{}按钮)? -
你想要的错误信息不正确。仅允许输入的第一个数字为零 (
value1)。x/0未定义,即使对于x==0。 -
请发布实际可编译的代码。这个区块在哪里关闭?
if (value1 % value2 == 0 ) {