一道题不会卡住了
为小学生输入一个简单算数练习程序,能够完成任意两个10以内的正整数的加减乘除操作,要求能够提示输入答案,能够判断答案是否正确。
#include "stdafx.h"
#include "math.h"
#include"stdlib.h"
#include"time.h"
int main()
{
int i,j,a[10],answer,answer1;
char s;
srand((int)time(0));
for(i=0;i<10;i++)
{
j=1+(int)(10.0*rand()/(RAND_MAX+1.0));
a[i]=j;
}
int choose=1+(int)(4.0*rand()/(RAND_MAX+1.0));
if(choose==1){
s='+';answer=a[4]+a[5];}
else if(choose==2){
s='-';answer=a[4]-a[5];}
else if(choose==3){
s='*';
answer=a[4]*a[5];}
else {s='÷';
answer=a[4]/a[5];}
printf("%d %c %d = ",a[4],s,a[5]);
scanf("%d",&answer1);
if(answer1==answer)
printf("答案正确");
else printf("答案错误");
return 0;
}