#define _CRT_SECURE_NO_WARNINGS 1#includestdiohint mainvoid int ad = 0 bd = 0 cd = 0; printfn输入一个正整数; scanfd &ad; cd = ad; do bd = 10 bd + cd 10; cd = cd 10; while cd; printfn颠倒的数字 d 是 d adbd
这段代码有以下错误:
-
在第一个scanf语句中,应该使用"&"符号来获取输入的字符,即
scanf("%c", &another_game); -
在第二个scanf语句中,应该使用"&"符号来获取输入的字符,即
scanf("%c", &another_game); -
在do-while循环的条件判断中,应该使用双引号括起来的字符常量,即
while(toupper(another_game) == 'Y'); -
缺少头文件
<ctype.h>来使用toupper函数,应该在开头添加#include<ctype.h>。
修正后的代码如下:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char another_game = 'Y';
printf("\n扮演简单西蒙");
printf("注意屏幕上的数字序列");
printf("\n小心观察,因为数字只显示一秒钟 !");
printf("\n编译器会重新编译它们,然后提示您");
printf("输入相同的序列");
printf("\n当你这样做时,你必须在数字之间加空格.\n");
printf("\n祝你好运\n按Enter键播放\n");
scanf("%c", &another_game);
do
{
printf("\n你想再玩一次吗 (y/b)?");
scanf(" %c", &another_game);
} while (toupper(another_game) == 'Y');
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/hZFm 著作权归作者所有。请勿转载和采集!