我将输入存储在一个变量中,然后将该值分配给另一个变量这是一种不好的做法吗?

问题描述

我想写好代码。我刚刚开始阅读Clean Code,我正在努力遵循它的建议。

我的问题的一个例子是:

#include <cs50.h>
#include <stdio.h>

int llamasBorn(int n);
int llamasDeceased(int n);

int main(void)
{
    // Prompt for start size
    int startSize;
    do
    {
        startSize = get_int("Start size: "); //-----> WATCH HERE!
    }
    while (startSize < 9);

    // Prompt for end size
    int endSize;
    do
    {
        endSize = get_int("End size: ");
    }
    while (endSize < startSize);

    // Calculate number of years until we reach threshold
    int yearsUntilThreshold = 0;
    int currentSize = startSize; //-----> AND HERE!    
    while (currentSize < endSize)
    {
        currentSize = currentSize + llamasBorn(currentSize) - llamasDeceased(currentSize);
        yearsUntilThreshold++;
    }

    // Print number of years
    printf("Years: %i\n",yearsUntilThreshold);
}

// Define method for the number of new llamas per year
int llamasBorn(int n)
{
    int born = n / 3;
    return born;
}

// Define method for the number of dead llamas per year
int llamasDeceased(int n)
{
    int deceased = n / 4;
    return deceased;
}

我想知道根据变量输入时的含义为其命名,然后将其存储在另一个变量中以增强下一段代码的可读性是否太过分了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...