C language randomly select two integers and add subtraction to form a formula requiring students to answer __c language

Source: Internet
Author: User
Tags rand

Study questions "for primary 1-2-year students, randomly selected two integers and addition and subtraction to form a formula to ask the students to answer." Requirements (1) only out of 10 questions, 10 points per title, program at the end of the display of learning
(2) To ensure that the formula does not exceed the level of 1-2 grade, only to allow 50 of the addition and subtraction, do not allow two of the sum or the difference is beyond the 0~50 range, negative numbers are not allowed
(3) Each question student has three times to enter the answer, when the student enters the wrong answer, reminds the student to re-enter, if three times the opportunity finishes then outputs the correct answer; (4) for each
The first time the students input the correct answer to 10 points, the second input the correct answer to 7 points, the third input the correct answer to get 5 points, otherwise do not score; (5) When the student has entered the correct number
, the evaluation results are randomly displayed, such as "right!", "correct!", "That's the answer" and so on, and if the answer is wrong, follow the "no,the answer is ..." Output answer
Case.

/* Random output 2 number algorithm--apxar*/


/* Random output 2 number algorithm--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 Result: You typed the correct answer!") \ n ');
score+=10;
}

Else
{
while (j<=3)
{
printf ("\ n answer error, please re-enter:");
scanf ("%d", &answer);
if (sum==answer)
{
printf ("\ n Result: You typed the correct answer!") \ n ');
k++;

if (k==2)
{score+=7;}
else if (k==3)
{score+=5;}

Break

}
Else

{k++;}

j + +;

}
if (j>3)
printf ("\ n the correct answer for this question is:%d\n", sum);

}

}
Else

i--;
}
printf ("\ n Total%d questions, your total score is%d\n \ n", I-1,score);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.