First, the topic
Please write a "software" that can automatically generate primary arithmetic topics. Allow the program to accept the user to enter the answer, and determine the right and wrong. Finally, the total number of pairs/errors is given.
Second, demand analysis
1, this software can choose the required arithmetic symbol, namely add, subtract, multiply, divide.
2, for the user to select the operation symbol can automatically generate two random numbers of integers want x, Y.
3, the software can manually input the results of the operation, the user to determine the correct answer to the wrong.
4, the correct answer to the user can be counted on the wrong number.
Third, design
For pupils to do the number of questions and correct and wrong number of questions can be counted to help users to count the answer.
Four, the code
#include"stdio.h"#include"windows.h"intright=0, wrong=0;voidJia () {intx, Y, Z X=rand ()% -; Y=rand ()% -; printf ("Please enter your answer:%d+%d=", x, y); scanf ("%d",&z); if(x+y!=z) {printf ("Answer error!\n"); Wrong++; } Else{printf ("Answer right!\n"); Right++; } }voidJian () {intx, Y, Z X=rand ()% -; Y=rand ()% -; printf ("Please enter your answer:%d-%d=", x, y); scanf ("%d",&z); if(x-y!=z) {printf ("Answer error!\n"); wrong++; } Else{printf ("Answer right!\n"); Right++; } }voidCheng () {intx, Y, Z X=rand ()% -; Y=rand ()% -; printf ("Please enter your answer:%d*%d=", x, y); scanf ("%d",&z); if(x*y!=z) {printf ("Answer error!\n"); Wrong++; } Else{printf ("Answer right!\n"); Right++; } }voidChu () {intx, Y, Z X=rand ()% -; Y=rand ()% -+1; printf ("Please enter your answer:%d/%d=", x, y); scanf ("%d",&z); if(x/y!=z) {printf ("Answer error!\n"); Wrong++; } Else{printf ("Answer right!\n"); Right++; }}voidMain () {intchoise,sum=0; printf ("\n\n\t\t Welcome to my C-Language four OP program system!\n"); System ("Pause"); System ("CLS"); while(1) {printf ("\n\n\t\t\t Please select the calculation symbol: \ n addition (input 1) \ t subtraction (input 2) \ t multiplication (input 3) \ t Division (input 4) \ n"); if(sum==0) scanf ("%d",&choise); Switch(choise) { Case 1: Jia (); Break; Case 2: Jian (); Break; Case 3: Cheng (); Break; Case 4: Chu (); Break; } printf ("Please select: \ t continue (input 1) \ t Re (enter 2) \ t to exit (enter 3) \ n"); scanf ("%d",&sum); if(sum==1) sum=1; if(sum==2) sum=0; if(sum==3) Break; } printf ("you've done%d questions, correct%d, error%d!\n", right+Wrong,right,wrong); System ("Pause");}
Five, run the code
Six, PSP timing
Vii. Summary
For this assignment, I still have some problems, for example, is not very familiar with writing code, plus the PSP timing is not very understanding. But the biggest gain of my homework is a little interest in software engineering.
Software Engineering (second job)