c语言随机选择两个整数和加减法形成算式要求学生解答

来源:互联网 发布:深入.net平台和c 编程 编辑:程序博客网 时间:2024/05/18 01:13

思考题】面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答。要求(1)只出10道题,每题10分,程序结束时显示学
生得分;(2)确保算式没有超出1~2年级的水平,只允许进行50以内的加减法,不允许两数之和或之差超出0~50的范围,负数更是不允许的
;(3)每道题学生有三次机会输入答案,当学生输入错误答案时,提醒学生重新输入,如果三次机会结束则输出正确答案;(4)对于每道
题,学生第一次输入正确答案得10分,第二次输入正确答案得7分,第三次输入正确答案得5分,否则不得分;(5)当学生输入了正确得数后
,随机显示评价结果,例如“Right!”、“Correct!”,“That’s the answer”等,若答案错误,则按照“No,the answer is …”输出答
案。

 

/*随机输出2个数算法--Apxar*/

 


/*随机输出2个数算法--Apxar*/

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{

 int i,j,k=2,num1,num2,sum=0,answer,score=0,xiabiao,temp;
    char fuhao[2]={'+','-'};
    srand((int)time(0));

  for(i=1;i<=10;i++)
  {
 
 xiabiao=rand()%2;
    num1=rand()*50/32767;
    num2=rand()*50/32767;

    if(xiabiao==0)
 { sum=num1+num2;}
    else
 { sum=num1-num2;}    
  
    if(sum>=0&&sum<=50)
 { 
         j=2;
         k=1;

         printf("\n(%d).\n",i);
         printf("%7d\n",num1);
         printf("%c\n",fuhao[xiabiao]);
         printf("%7d\n",num2);
         printf("------------\n");
      printf("     ");
         scanf("%d",&answer);
 
       if(sum==answer)

    {
        printf("\n结果:你输入的答案正确! \n\n");
     score+=10;
    }

    else
    {
          while(j<=3)
    {
                printf("\n答案错误,请重新输入:");
                   scanf("%d",&answer);
                    if(sum==answer)
      {
     printf("\n结果:你输入的答案正确! \n\n");
                    k++;
                   
     if(k==2)
     { score+=7;}
                    else if(k==3)
     { score+=5;}

      break;

      }
        else

     { k++;}
                     
          j++;
    
    }
            if(j>3)
                     printf("\n该题正确答案为:%d\n",sum);

   }

 

 }
     else

   i--;
  }
     printf("\n共%d道题目,你的总分为%d\n \n",i-1,score);
}

原创粉丝点击