20160317 second question

Source: Internet
Author: User

Code review

My small partner is Yu Yue, she uses the C language, C-free to write the arithmetic, the following is her code

#include <stdio.h>#include<stdlib.h>#include<time.h>Main () {intA,b,op,os; printf ("[arithmetic to challenge]\n"); aq1:printf ("Choose the algorithm you want to challenge \ n");p rintf ("1. Addition 2. Subtraction 3. Multiplication 4. Division \ n"); scanf ("%d",&op);Switch(OP) {aq: Case 1: Srand ((unsigned) time (NULL)); a=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d +%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d +%d =%d\n\n\n", a,b,a+b);Gotoaq1;}ElseGotoaq; Break; at: Case 2: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d-%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d-%d =%d\n\n\n", a,b,a-b);Gotoaq1;}ElseGotoat ; Break; AQ2: Case 3: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d *%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d *%d =%d\n\n\n", a,b,a*b);Gotoaq1;}ElseGotoaq2;aq3: Case 4: A=rand ()% -+1; B=rand ()% -+1;p rintf ("The topic is:%d/%d =? \ n", A, b);p rintf ("1. Review the answer 2. Do the next question \ n"); scanf ("%d",&OS);if(os==1) {printf ("%d/%d =%d\n\n\n", a,b,a/b);Gotoaq1;}ElseGotoaq3; Break;}}

Every line of code has been checked, there is no problem, there is no unnecessary code, and the entire program can be run out. But she and I came up with the same problem, all without comment. and code writing is not standardized, there is no indentation, such as see If,else statements, because are left-aligned, it is not easy to find, and then combine the above content, it is not clear, which caused the code overall readability is not high, not easy to maintain.

20160317 second question

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.