Arithmetic implementing user input answers and counting the correct number

Source: Internet
Author: User

One, design ideas:

The goal of this implementation is to implement the user input answer on the basis of the previous code, and to determine whether the answer is correct and statistics, and then output the correct number of answers.

The idea of judging whether the answer is correct is to define wrong (to count the number of errors) on the previous basis, K1, parameters.

In the void display function, we define the judgment of the answer and the statistics of the correct error, and finally, in the main function, through the call of the pointer to achieve the correct answer and the number of errors statistics.

Two, source code:

#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
void Display (int p); Output topics
int wrong=0,right=0;
int a[100],b[100],c[100];
int i;
void Display (int p,int *ri,int *wr,int i)//Output topic
{
int k1=0;

if (p==0)
{
if (c[i]==0)
{
printf ("%d+%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &K1);
if (K1!=a[i]+b[i])
wrong++;
Else
right++;
}
else if (c[i]==1)
{
printf ("%d-%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &K1);
if (K1!=a[i]-b[i])
wrong++;
Else
right++;
}
else if (c[i]==2)
{
printf ("%d*%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &K1);
if (K1!=a[i]*b[i])
wrong++;
Else
right++;
}
Else
{
printf ("%d/%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &K1);
if (K1!=a[i]/b[i])
wrong++;
Else
right++;
}

}
Else
{
if (c[i]==0)
{
printf ("%d+%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &AMP;K1);
if (K1!=a[i]+b[i])
wrong++;
Else
right++;
}
else if (c[i]==1)
{
printf ("%d-%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &AMP;K1);
if (K1!=a[i]-b[i])
wrong++;
Else
right++;
}
else if (c[i]==2)
{
printf ("%d*%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &AMP;K1);
if (K1!=a[i]*b[i])
wrong++;
Else
right++;
}
Else
{
printf ("%d/%d=\n", A[i],b[i]);
printf ("Please enter results! ");
scanf ("%d", &AMP;K1);
if (K1!=a[i]/b[i])
wrong++;
Else
right++;
}

if ((i+1)%p==0)
printf ("\ n");
}
*ri=right;
*wr=wrong;
}
void Carry (int *q,int *ri,int *WR)//Perform all procedures, add error handling
{
Int J;
int t;
int m;
int n;
int q;
int D;
int p=3;
int R;
int wrong=0;
int right=0;
printf ("1. Please choose whether there is a multiplication method (0: Yes 1: NO) \ n");
scanf ("%d", &m);
if (m!=0&&m!=1)
{
printf ("Input error, please re-enter!") \ n ");
Carry (Q,RI,WR);
}
printf ("2. Please enter the value range: (0-?) \ n ");
scanf ("%d", &r);
printf ("3." Please select Plus or minus with or without negative numbers: (0:1: none) \ n ");
scanf ("%d", &n);
if (n!=0&&n!=1)
{
printf ("Input error please re-enter!") \ n ");
Carry (Q,RI,WR);
}
if (m==0)
{
printf ("4. Please select Departure has no number: (0:1: none) \ n");
scanf ("%d", &d);
if (d!=0&&d!=1)
{
printf ("Input error please re-enter!") \ n ");
Carry (Q,RI,WR);
}
}
printf ("5. Please enter the number of questions: \ n");
scanf ("%d", q);
if (*q<=0)
{
printf ("Input error please re-enter!") \ n ");
Carry (Q,RI,WR);
}
printf ("6. Please select the printing method: 0 for line-by-row printing, enter another number is a row of several columns \ n");
scanf ("%d", &p);
if (p<0)
{
printf ("Input error please re-enter!") \ n ");
Carry (Q,RI,WR);
}
for (int i=0;i<*q;i++)
{
A[i]=rand ()%r;
B[i]=rand ()%r;
C[i]=rand ()%4;
if (c[i]==3&&b[i]==0)
{
b[i]++;
}
for (j=0;j<i;j++)//To determine whether the problem is repeated, if repeated a[i]++
if (A[j]==a[i]&&b[j]==b[i]&&c[j]==c[i])
a[i]++;
if (m==0&&n==0&&d==0)
{
Display (P,ri,wr,i);
}
else if (m==1)//No Multiplication method
{
if (c[i]>=2)
C[i]=c[i]-2;
Display (P,ri,wr,i);
}
else if (m==0&&n==1&&d==0)//No negative, and dividend is greater than divisor
{
if (A[i]<b[i])
{
T=a[i];
A[i]=b[i];
b[i]=t;
}
Display (P,ri,wr,i);
}
Else
{
if (c[i]==3)
{
if (A[i]<b[i])
{
T=a[i];
A[i]=b[i];
b[i]=t;
}
while (a[i]%b[i]!=0)//No number
b[i]++;
}
Display (P,ri,wr,i);
}
}
}

void Main ()
{
int tishu=0;
int wrong1=0,right1=0;
Carry (&TISHU,&RIGHT1,&WRONG1);
printf ("You have done a total of" the word, the correct number of ' right ', the number of errors ' wrong ' \ n ');
cout<< "You always Do" <<tishu<< ", correct" <<right1<< "The Tao, Error" <<wrong1<< "Road" << Endl
}

Third, the result of the operation:

Iv. the results are summarized as follows:

In the initial thinking is to define the void disply function in the definition of the answer and statistical strategy, at first I put the wrong and right variables in the disply function, and finally led to the results of the operation has been output correct answer 1 error 0, The wrong and right are restored to 0 each time the function is executed, which results in errors in the wrong and correct statistics. After the first correction found still is not correct, because I forgot the disply function in the module is a separate relationship so to use the else if instead of the original if to represent. However, after running the result is still error, the output is correct and the number of errors is always reversed, and found that in the main function, the return of the pointer is wrong, resulting in a result error. This is the problem encountered, these problems are caused by carelessness, there is a logic error. In the final analysis is the foundation is too poor, lack of practice!

Arithmetic implementing user input answers and counting the correct number

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.