elementary school quiz

Project Primary Student Test 16 credit hours

Problem description: For students in grades 1 and 2 of primary school, randomly select two integers to add and subtract to form an equation and ask students to answer.

1. basic requirements

(1) The computer randomly assigns 10 questions, each with 10 points, and the student's score will be displayed at the end of the program;

(2) Make sure that the calculation formula does not exceed the level of grades 1 and 2. Only addition and subtraction within 50 is allowed, and the sum or difference of two numbers is not allowed to exceed the range of 0 to 50, and negative numbers are not allowed;

(3) Students have three chances to input the answer for each question. When the student inputs the wrong answer, the student is reminded to re-input, and if the three chances are over, the correct answer is output;

(4) For each question, students will get 10 points for the correct answer for the first time, 7 points for the correct answer for the second time, and 5 points for the correct answer for the third time, otherwise no points are awarded;

 (5) "SMART" is displayed for the total score above 90, "GOOD" for 80-90, "OK" for 70-80, "PASS" for 60-70, and "TRY AGAIN" below 60.


#include <iostream>  

using namespace std;  
#include <stdlib.h>  
#include <time.h>  
void create(int &a,int &b,int &c)
{
int a1,b1;
while(1)
{
a1=rand()%50;  
                b1=rand()%50;
               if(a1+b1<=50&&a1-b1<=50&&a1-b1>=0)
               break;
}
a=a1;b=b1;
c=rand()%2;
}
int main()  
{  
     int ans,score=0;
int a,b,c,k=0;  
     char s;
    srand((unsigned)time(NULL)); 
while(k!=10)
{
k++;
cout<<"第"<<k<<"个题目是:";
    create(a,b,c);
    if(c==0)
    s='+';
    else
    s='-';
        cout<<a<<s<<b<<"=";
        int k1=3;
int f=0;
    while(k1--)
    {      cin>>ans;         if((c==0&&ans==a+b)||(c==1&&ans==a-b))         { f=1; if(k1==2) score+=10; if(k1==1) score+=7; if(k1==0) score+=5;             break; } else  if(k1!=0) cout<<"请重新输入"<<endl;  } if(f==0) { cout<<"正确答案是:"; if(c==0) cout<<a+b<<endl; else  cout<<a-b<<endl; } }
   



       
       
         
         
         
         
         














   cout<<score<<endl;
     if(score>=90)
     cout<<"SMART";
     else if(score>=80)
     cout<<"GOOD";
     else if(score>=70)
     cout<<"OK";
     else if(score>=60)
    cout<<"PASS";
    else
    cout<<"TRY AGAIN";
return 0;  
    
}  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325608783&siteId=291194637