zoukankan      html  css  js  c++  java
  • 20160317第二题

    代码复审

    我负责的小伙伴是于悦,她用的是c语言,c-free来编写的四则运算,以下是她的代码

    #include<stdio.h>
     
    #include<stdlib.h>
    #include<time.h>
    main()
    {
    int a,b,op,os;
     
    printf(" [四则运算来挑战]
    ");
    aq1:    printf("选择你想挑战的运算法则
    ");
    printf("1.加法 2.减法 3.乘法 4.除法
    ");
    scanf("%d",&op);
    switch(op)
    {
    aq: case 1:
    srand((unsigned)time(NULL));
    a=rand()%100+1;b=rand()%100+1;
    printf("题目为:%d + %d = ?
    
    ",a,b);
    printf("1.查看答案 2.做下一题
    ");
    scanf("%d",&os);
    if(os==1)
    {printf("%d + %d =%d
    
    
    ",a,b,a+b);
    goto aq1;
    }
    else
    goto aq;
    break;
    at:  case 2:a=rand()%100+1;b=rand()%100+1;
    printf("题目为:%d - %d = ?
    
    ",a,b);
    printf("1.查看答案 2.做下一题
    ");
    scanf("%d",&os);
    if(os==1)
    {printf("%d - %d =%d
    
    
    ",a,b,a-b);
    goto aq1;
    }
    else
    goto at;
    break;
    aq2:     case 3:
    a=rand()%100+1;b=rand()%100+1;
    printf("题目为:%d * %d = ?
    
    ",a,b);
    printf("1.查看答案 2.做下一题
    ");
    scanf("%d",&os);
    if(os==1)
    {printf("%d * %d =%d
    
    
    ",a,b,a*b);
    goto aq1;
    }
    else
    goto aq2;
    aq3:     case 4:
    a=rand()%100+1;b=rand()%100+1;
    printf("题目为:%d / %d = ?
    
    ",a,b);
    printf("1.查看答案 2.做下一题
    ");
    scanf("%d",&os);
    if(os==1)
    {printf("%d / %d =%d
    
    
    ",a,b,a/b);
    goto aq1;
    }
    else
    goto aq3;
    break;
    }
    }

    代码的每一行都检查过了,都是没有问题的,也没有一些没必要的代码,而且整个程序都可以运行出来。但是她和我出现了同样的问题,都是没有注释。而且代码的编写也不规范,都没有缩进,比如看if,else语句,因为都是左对齐的,很不容易去找到,再结合上面的内容,很不容看明白,这就造成了代码整体的可读性不高,不容易进行维护。

  • 相关阅读:
    lua 取table长度
    [转] 理解 LSTM 网络
    [转]An Intuitive Explanation of Convolutional Neural Networks
    [转]How rival bots battled their way to poker supremacy
    【转】Principles of training multi-layer neural network using backpropagation
    [转]霍夫丁不等式与真实的机器学习
    [转]PLA算法总结及其证明
    jinja2 宏的简单使用总结(macro)
    Python 装饰器
    PYTHON REQUESTS的安装与简单运用
  • 原文地址:https://www.cnblogs.com/dys123hahabalala/p/5313780.html
Copyright © 2011-2022 走看看