Requirements Analysis:
Basic functions
Achieve subtraction method within 100
Design:
First choose whether to enter the test state, if you choose to enter the test, then randomly produce 100 within the subtraction of the problem of the thought of the operation
Use the switch selection statement to choose what to do (0 for addition, 1 for subtraction, 2 for division, 3 for multiplication) and for related evaluations based on the number of questions answered correctly.
Code implementation
#include <iostream> #include <ctime> using namespace std; int main () {int a,b,c,r=0,x,z,i,y,k; Srand (Time (NULL)); cin>>z; if (z==1) {cout<< "Test begins! \ n "; for (i=1;i<11;i++) {A=rand ()%100; B=rand ()%100; X=rand ()%4; K=rand ()%10; Switch (x) {case 0: {y=a+b; cout<< "Please read the question: \ t"; cout<<a<< "+" <<b<< "="; cin>>c; if (y==c) {r+=1; cout<< "Correct, cumulative correct number of questions for" <<R<< "\ n"; } else cout<< "the wrong answer, keep trying!" \ n "; Break } Case 1: {if (b>a) {z=a; A=b; B=z; } y=a-b; cout<< "Please read the question: \ t"; cout<<a<< "-" <<b<< "="; cin>>c; if (y==c) {r+=1; cout<< "Correct, cumulative correct number of questions for" <<R<< "\ n"; } else cout<< "the wrong answer, keep trying!" \ n "; Break Case 2: {if (a>10) {A=A/10; } if (b>10) {B=B/10; } y=a*b; cout<< "Please read the question: \ t"; cout<<a<< "*" <<b<< "="; cin>>c; if (y==c) {r+=1; cout<< "Correct, cumulative correct number of questions for" <<R<< "\ n"; } else cout<< "the wrong answer, keep trying!" \ n "; Break } Case 3: {if (b>10) {b= B/10; } if (! ( a%b==0)) {a=b*k; } y=a/b; cout<< "Please read the question: \ t"; cout<<a<< "/" <<b<< "="; cin>>c; if (y==c) {r+=1; cout<< "Correct, cumulative correct number of questions for" <<R<< "\ n"; } else cout<< "the wrong answer, keep trying!" \ n "; Break }}}}} else {cout<< "test completed, thank you for your participation \ n"; Return0; } switch (R) {case 10:cout<< "It's a genius!" \ n "; break; Case 9:cout<< "how clever!" \ n "; break; Case 8:cout<< "Good! \ n "; break; Case 7:cout<< "A lot of refueling!" \ n "; break; Case 6:cout<< "Just passed, and you have to practice more!" \ n "; break; Case 5:case 4:case 3:case 2:case 1:case 0:cout<< "less than lattice! \ n "; break; } return 0; }
Summary: Pay attention to the rationality of logic, even if it can be run or it may be a dead loop causes the program to not achieve the expected function.
Software Engineering Second Job