![]() |
|
ja tentei quase tudo - Printable Version +- SimRacing Portugal Forum (https://www.simracingportugal.net/forum) +-- Forum: Geral (https://www.simracingportugal.net/forum/forumdisplay.php?fid=5) +--- Forum: Geral (https://www.simracingportugal.net/forum/forumdisplay.php?fid=85) +--- Thread: ja tentei quase tudo (/showthread.php?tid=1960) |
ja tentei quase tudo - edimar0007 - 22-12-2007 galera to recorrendo a ajuda de quem souber preciso desse programinha para completar um projeto meu Escrever um programa para processar 10 medidores de energia. Os dados que serão processados devem ser: - Número do medidor - Leitura anterior - Leitura atual - Tipo do cliente Os tipos de clientes possíveis são: 1 Residencial 2 Comercial 3 Rural O valor do KWA de energia é: Cliente residencial: R$ 0,09 Cliente Comercial: R$ 0,13 Cliente Rural: R$ 0,04 Criticas a serem realizadas: Tipo do cliente: Apenas 1, 2 ou 3 Número do medidor, leitura anterior e leitura atual: não pode ser 0 Leitura atual: Não pode ser menor que leitura anterior Obs.: Valor da conta mínima: R$ 15,00 Expl:Se der 9 mostra R$15,00 Mostrar: Medidor Consumo Valor da Conta -------- --------- 99,99 -------- --------- 99,99 -------- --------- 99,99 Total Residencial: 99,99 Total Comercial: 99,99 Total Rural: 99,99 TOTAL GERAL: 99,99 serei eternamente grato a quem me ajudar ja tentei quase tudo - Alexandre Caetano - 22-12-2007 mostra o que já tens, ou onde tens o erro. ja tentei quase tudo - Rui Azevedo - 22-12-2007 Vê se isto te serve. Foi feito à pressa por isso é possível que tenha algun(s) bug(s) [codebox]#include <stdio.h> unsigned int anterior[10] = {10,3,2,1,5,7,8,1,1,5}; unsigned int actual[10] = {12,453,47,856,33,78,33,93,784,22}; unsigned int tipoCliente[10] = {1,2,3,1,2,3,1,2,3,1}; float residencial = 0.09; float comercial = 0.13; float rural = 0.04; float residencialTotal = 0; float comercialTotal = 0; float ruralTotal = 0; int i = 0; int verificaClientes(int array[]) { for(i = 0; i < 10; i++) if(array[i] < 1 || array[i] > 3) return -1; return 0; } int verificaLeituras(int anterior[], int actual[]) { for(i = 0; i < 10; i++) if(anterior[i] == 0 || actual[i] == 0 || (anterior[i]>actual[i]) ) return -1; return 0; } float calcValor(int indice) { int temp = actual[indice]-anterior[indice]; int tipo = tipoCliente[indice]; int valor = 0; switch(tipo) { case 1: valor=(temp*residencial); if(valor<15) valor = 15; residencialTotal=residencialTotal+valor; break; case 2: valor=(temp*comercial); if(valor<15) valor = 15; comercialTotal=comercialTotal+valor; break; case 3: valor=(temp*rural); if(valor<15) valor = 15; ruralTotal=ruralTotal+valor; break; } return valor; } int main(void) { if(verificaClientes(tipoCliente) < 0) printf("Erro em tipo de clientes\n"); if(verificaLeituras(anterior, actual) < 0) printf("Erro nas leituras\n"); int j = 0; printf("Medidor\t, Consumo\t,Valor da Conta\n"); for(j = 0; j < 10; j++) printf("%d,\t %d,\t %6.2f\n", actual[j], actual[j]-anterior[j], calcValor(j) ); printf("Total Residencial: %.2f\nTotal Comercial: %.2f\nTotal Rural: %.2f\n", residencialTotal, comercialTotal, ruralTotal); return 0; } [/codebox] ja tentei quase tudo - edimar0007 - 25-12-2007 valew galera ja judou |