小学校四則演算
1707 ワード
#include
#include
#include
#include
int menu()
{
int choice;
system("cls");
printf("1:
");
printf("2:
");
printf("3:
");
printf("4:
");
printf("0:
");
printf(" :");
scanf("%d",&choice);
while(choice<0||choice>4)
{
printf(" :");
scanf("%d",&choice);
}
return choice;
}
void Start_Game(int n)
{
int sum=0;//
int correct=0;//
int a,b;//
int ans;//
char temp;
system("cls");
while(1)
{
srand(time(NULL));
a=rand()%50;
b=rand()%50;
while(n==4 && a%b!=0)
{
a=rand()%50;
b=rand()%50;
}
if(n==1)
{
printf("%d + %d = ",a,b);
scanf("%d",&ans);
if(ans == a+b)
{
correct++;
}
}
if(n==2)
{
printf("%d - %d = ",a,b);
scanf("%d",&ans);
if(ans == a-b)
{
correct++;
}
}
if(n==3)
{
printf("%d * %d = ",a,b);
scanf("%d",&ans);
if(ans == a*b)
{
correct++;
}
}
if(n==4)
{
printf("%d / %d = ",a,b);
scanf("%d",&ans);
if(ans == a/b)
{
correct++;
}
}
sum++;
printf(" ?(Y/N):");
fflush(stdin);
scanf("%c",&temp);
if(temp=='n'||temp=='N')
{
break;
}
}
printf(" %d
",sum);
printf(" %d
",correct);
printf(" %.2f%%
",correct*100.0/sum);
system("pause");
}
int main()
{
int choice=menu();
Start_Game(choice);
return 0;
}