编了个四则运算的,可是电脑抽取的随机数又是一样的,不知道怎么该
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int a;
int b;
int starbar();
int add(); //加
int minu(); //减
int times(); //乘
int divide(); //除
int all(); //综合
int jduge(); //判断
int c,d,e;
int main (void)
{
int f;
starbar();
printf(" 四则运算1.0版\n");
printf("请选择:1.加 2.减\n");
printf(" 3.乘 4.除\n");
printf(" 5.综合 6.退出\n");
starbar();
scanf("%d",&f);
time_t t;
srand(time(NULL));
a=rand()%10+1;
srand(time(NULL));
b=rand()%10+1;
switch(f)
{
case 1:
for(e=0;e<=10;e++)
{add();
jduge();}
break;
case 2:for(e=0;e<=10;e++)
{minu();
jduge();}
break;
case 3:
for(e=0;e<=10;e++)
{times();
jduge();}
break;
case 4:
for(e=0;e<=10;e++)
{
divide();
jduge();
}
break;
case 5:
for(e=0;e<=10;e++)
{all();
jduge();}
break;
case 6:
printf("Bye!\n");
break;
}
system("pause");
return 0;
}
int starbar (void)
{
int n;
for(n=1;n<=40;n++)
printf("*");
printf("\n");
}
int add (void)
{
printf("%d+%d=",a,b);
scanf("%d",&c);
d=a+b;
}
int minu (void)
{
printf("%d-%d=",a,b);
scanf("%d",&c);
d=a-b;
}
int times (void)
{
printf("%d*%d=",a,b);
scanf("%d",&c);
d=a*b;
}
int divide (void)
{
printf("%d/%d=",a,b);
scanf("%d",&c);
d=a/b;
}
int all (void)
{
int i;
time_t t;
srand(time(NULL));
i=rand()%4+1;
switch(i)
{
case 1:for(e=0;e<=10;e++)
{add();
jduge();
}
case 2:for(e=0;e<=10;e++)
{
minu();
jduge();
}
case 3:for(e=0;e<=10;e++)
{
times();
jduge();
}
case 4:for(e=0;e<=10;e++)
{
divide();
jduge();
}
}
}
int jduge (void)
{
if(d==c)
printf("答对\n");
else
printf("打错了,应该是%d\n",d);
}
谢谢啦~
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int a;
int b;
int starbar();
int add(); //加
int minu(); //减
int times(); //乘
int divide(); //除
int all(); //综合
int jduge(); //判断
int c,d,e;
int main (void)
{
int f;
starbar();
printf(" 四则运算1.0版\n");
printf("请选择:1.加 2.减\n");
printf(" 3.乘 4.除\n");
printf(" 5.综合 6.退出\n");
starbar();
scanf("%d",&f);
time_t t;
srand(time(NULL));
a=rand()%10+1;
srand(time(NULL));
b=rand()%10+1;
switch(f)
{
case 1:
for(e=0;e<=10;e++)
{add();
jduge();}
break;
case 2:for(e=0;e<=10;e++)
{minu();
jduge();}
break;
case 3:
for(e=0;e<=10;e++)
{times();
jduge();}
break;
case 4:
for(e=0;e<=10;e++)
{
divide();
jduge();
}
break;
case 5:
for(e=0;e<=10;e++)
{all();
jduge();}
break;
case 6:
printf("Bye!\n");
break;
}
system("pause");
return 0;
}
int starbar (void)
{
int n;
for(n=1;n<=40;n++)
printf("*");
printf("\n");
}
int add (void)
{
printf("%d+%d=",a,b);
scanf("%d",&c);
d=a+b;
}
int minu (void)
{
printf("%d-%d=",a,b);
scanf("%d",&c);
d=a-b;
}
int times (void)
{
printf("%d*%d=",a,b);
scanf("%d",&c);
d=a*b;
}
int divide (void)
{
printf("%d/%d=",a,b);
scanf("%d",&c);
d=a/b;
}
int all (void)
{
int i;
time_t t;
srand(time(NULL));
i=rand()%4+1;
switch(i)
{
case 1:for(e=0;e<=10;e++)
{add();
jduge();
}
case 2:for(e=0;e<=10;e++)
{
minu();
jduge();
}
case 3:for(e=0;e<=10;e++)
{
times();
jduge();
}
case 4:for(e=0;e<=10;e++)
{
divide();
jduge();
}
}
}
int jduge (void)
{
if(d==c)
printf("答对\n");
else
printf("打错了,应该是%d\n",d);
}
谢谢啦~