gpt4 book ai didi

C Borland 编译器错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:39:58 25 4
gpt4 key购买 nike

回到 Borland C 编译器的基础知识。我不断收到以下消息,这让我发疯,因为我找不到分号应该放在哪里或为什么要分号

>bcc32 -v- -w -O1 oddEven.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
oddEven.c:
Error E2378 oddEven.c 16: For statement missing ; in function main()
*** 1 errors in Compile ***
>Exit code: 1

这是我的代码,感谢您的提前帮助

/* Program to check if a given integer between 1 and 100 is odd or even
Date: 09/10/2015 */


#include <stdio.h>

main()
{
int input;

printf("\nPlease Enter A Number Between 1 and 100\n");
scanf("%d", &input);
printf("\nYou Entered %d\n", input);

//for loop used for error handling
for(input > 0 && input < 101)
{

if(input <= 0 && input > 100)

{
printf("Error!! Please Enter A Number Between 1 and 100");

}//end if 1


//modulo 2 to check for even divisibility
if(input % 2 == 0)
{
printf("\n %d is EVEN", input);
}//end if 2

else
{
printf("\n %d is ODD", input);
}//end else

}//end for loop

getchar();
getchar();

}//end main

最佳答案

这个:

for(input > 0 && input < 101)

是无效语法。应该是

while(input > 0 && input < 101)

但是你在输入任何有效的东西时都会有一个无限循环。它可能应该是 if,但是当用户输入无效数字时,不会打印任何错误消息。然后你应该移动

if(input <= 0 && input > 100)
{
printf("Error!! Please Enter A Number Between 1 and 100");
}//end if 1

if 之外。

还有很多其他问题。我建议你读一本很好的 C 书。

固定代码:

/* Note how this code is indented and looks clean */

#include <stdio.h>

int main(void) /* Valid signature of main */
{
int input, c; /* Note the extra variable */

printf("\nPlease Enter A Number Between 1 and 100\n");
scanf("%d", &input);

printf("\nYou Entered %d\n", input);

if(input <= 0 || input > 100) /* Note the use of || instead of && */
{
printf("Error!! Please Enter A Number Between 1 and 100 \n");
}
else /* Note the else */
{
if(input % 2 == 0)
{
printf("\n %d is EVEN \n", input);
}
else
{
printf("\n %d is ODD \n", input);
}
}

while((c = getchar()) != '\n' && c != EOF); /* Clear the stdin */
getchar(); /* Wait for a character */
}

关于C Borland 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33052776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com