程序代码:/* 你函数调用中好像每个函数都要用到a, b
在主函数中,都没定义,赋值,你就直接传递参数?? 很不能理解.
我把a, b定义为外部变量.
*/
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int Renwu1(void); // 因为a, b为外部变量了, 参数传递就省了.
int Renwu2(void); // 下面的函数都没定义. 我想是你没附上来.
int Renwu3(void);
int Renwu4(void);
int Renwu5(void);
int Renwu6(void);
int Time_a(void);
int Time_b(void);
int Jscf(void);
int Time(void);
static int a, b;
int main()
{
int n;
srand(time(NULL)); // 这个函数放在这里
printf("选择任务: (1~6)\n:");
while(scanf("%d",&n)!=1 && (n>6||n<1))
{
while(getchar() != '\n');
printf("选择任务: (1~6)");
}
switch (n)
{
case 1:
Renwu1(); // 函数调用不要加类型说明符了.
break;
case 2:
Renwu2();
break;
case 3:
Renwu3();
break;
case 4:
Renwu4();
break;
case 5:
Renwu5();
break;
case 6:
Renwu6();
break;
}
}
//任?1:
int Renwu1(void)
{
int i,p;
a = Time_a(); // 这里放到for () 外面.
b = Time_b();
for(i = 1;;i++)
{
printf("%d*%d = ",a,b);
scanf("%d",&p);
if(p == Jscf())
{
printf("Right!\n");
break; // 这里不跳出,你的就是个无限循环.
}
else printf("Wrong! Please try again.\n");
}
return 0;
}
int Jscf(void)
{
return a*b;
}
int Time_a(void)
{
return rand()%10+1;
}
int Time_b(void)
{
return rand()%10+1;
}[ 本帖最后由 pangshch 于 2013-11-22 18:13 编辑 ]








