From fc0855a07a8ff1e75a9b3441d4be25e451b903d2 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 8 Jul 2015 09:48:11 +0000 Subject: [PATCH] =?utf8?q?Pr=C3=A9-calcula=20o=20total=20de=20rendimentos.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ao invés de calcular duas vezes, tanto para declaração simples quanto completa, calcula o total de rendimentos uma única vez. --- calcula.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/calcula.c b/calcula.c index a6bac0e..a8accc3 100644 --- a/calcula.c +++ b/calcula.c @@ -23,7 +23,7 @@ #include #include -static long long total_rendimento(struct declaracao *dec) +static void total_rendimento(struct declaracao *dec) { long long tr = 0; struct rendimento *rendimento; @@ -31,7 +31,7 @@ static long long total_rendimento(struct declaracao *dec) for (i = 0; rendimento = list_get(dec->rendimento, i); i++) { tr += rendimento->rendimento; } - return tr; + dec->totalrendimento = tr; } static long long total_deducao(struct declaracao *dec) @@ -86,7 +86,7 @@ static long long imposto_simples(struct declaracao *dec) struct taxtable *tt; long long tr, td; tt = table2015; - tr = total_rendimento(dec); + tr = dec->totalrendimento; dec->totalrendimento = tr; if (tr / 5 < simples2015) td = tr / 5; @@ -104,9 +104,8 @@ static long long imposto_completa(struct declaracao *dec) return -EINVAL; } tt = table2015; - tr = total_rendimento(dec); + tr = dec->totalrendimento; td = total_deducao(dec); - dec->totalrendimento = tr; tr -= td; return imposto(tt, tr); } @@ -117,6 +116,7 @@ int calcula(struct declaracao *dec) if (dec->ano != 2015) { return -EINVAL; } + total_rendimento(dec); i_simples = imposto_simples(dec); i_completa = imposto_completa(dec); total_pago(dec); -- 2.20.1