Software Engineering Second Job

Source: Internet
Author: User

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

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.