#include <stdio.h>
int main( ) {
struct pessoas {
int codTC; //codigo do consumidor para falar se é 1-Residencial 2-Comercial 3-Industrial
int num; //numero do consumidor (vou colocar o numero referente ao cod para nao confundir)
float kwh; //Quilowatt-hora
} ;
struct pessoas consumidor[ 16 ] ;
float total, totalT, consumo1, consumo2, media;
int i = 0 ;
printf ( "\n Exercício desenvolvido considerando a tarifa do CIP - Contribuição Municipal\n " ) ; do {
printf ( "\n Tipo de consumidor, digite:\n 1 - Residencial\n 2 - Comercial\n 3 - Industrial: " ) ; scanf ( "%i" , & consumidor
[ i
] .
codTC ) ;
if ( consumidor[ i] .codTC == 1 ) {
printf ( "\n \n Digite o numero do consumidor: " ) ; scanf ( "%i" , & consumidor
[ i
] .
num ) ; printf ( "\n Digite a quantidade de kWh consumidos durante o mes: " ) ; scanf ( "%f" , & consumidor
[ i
] .
kwh ) ; //O total do valor sem tarifa, ou seja o custo total para cada consumidor;
total = consumidor[ i] .kwh * 0.3 ;
//O total do valor com tarifa, ou seja o total + tarifas
totalT = total + 5.17 ;
consumo1 = consumidor[ i] .kwh ;
} else if ( consumidor[ i] .codTC == 2 ) {
printf ( "\n \n Digite o numero do consumidor: " ) ; scanf ( "%i" , & consumidor
[ i
] .
num ) ; printf ( "\n Digite a quantidade de kWh consumidos durante o mes: " ) ; scanf ( "%f" , & consumidor
[ i
] .
kwh ) ; total = consumidor[ i] .kwh * 0.5 ;
//O total do valor com tarifa, ou seja o total + tarifas
totalT = total + 5.17 ;
consumo2 = consumidor[ i] .kwh ;
} else if ( consumidor[ i] .codTC == 3 ) {
printf ( "\n \n Digite o numero do consumidor: " ) ; scanf ( "%i" , & consumidor
[ i
] .
num ) ; printf ( "\n Digite a quantidade de kWh consumidos durante o mes: " ) ; scanf ( "%f" , & consumidor
[ i
] .
kwh ) ; total = consumidor[ i] .kwh * 0.7 ;
//O total do valor com tarifa, ou seja o total + tarifas
totalT = total + 5.17 ;
}
media = consumo1 + consumo2 / 2 ;
printf ( "\n O total de consumo e %.2f\n " , total
) ; printf ( "\n O custo total e %.2f\n " , totalT
) ; printf ( "\n A media de consumo dos consumidores 1 e 2 e %.2f\n " , media
) ; i++;
} while ( consumidor[ i - 1 ] .num != 0 ) ;
return ( 0 ) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCkgewogICAgc3RydWN0IHBlc3NvYXMgewogICAgICAgIGludCBjb2RUQzsgLy9jb2RpZ28gZG8gY29uc3VtaWRvciBwYXJhIGZhbGFyIHNlIMOpIDEtUmVzaWRlbmNpYWwgMi1Db21lcmNpYWwgMy1JbmR1c3RyaWFsCiAgICAgICAgaW50IG51bTsgLy9udW1lcm8gZG8gY29uc3VtaWRvciAodm91IGNvbG9jYXIgbyBudW1lcm8gcmVmZXJlbnRlIGFvIGNvZCBwYXJhIG5hbyBjb25mdW5kaXIpCiAgICAgICAgZmxvYXQga3doOyAvL1F1aWxvd2F0dC1ob3JhCiAgICB9OwoKICAgIHN0cnVjdCBwZXNzb2FzIGNvbnN1bWlkb3JbMTZdOwoKICAgIGZsb2F0IHRvdGFsLCB0b3RhbFQsIGNvbnN1bW8xLCBjb25zdW1vMiwgbWVkaWE7CiAgICBpbnQgaSA9IDA7CgogICAgcHJpbnRmKCJcbkV4ZXJjw61jaW8gZGVzZW52b2x2aWRvIGNvbnNpZGVyYW5kbyBhIHRhcmlmYSBkbyBDSVAgLSBDb250cmlidWnDp8OjbyBNdW5pY2lwYWxcbiIpOwogICAgZG8gewogICAgICAgIHByaW50ZigiXG5UaXBvIGRlIGNvbnN1bWlkb3IsIGRpZ2l0ZTpcbjEgLSBSZXNpZGVuY2lhbFxuMiAtIENvbWVyY2lhbFxuMyAtIEluZHVzdHJpYWw6ICIpOwogICAgICAgIHNjYW5mKCIlaSIsICZjb25zdW1pZG9yW2ldLmNvZFRDKTsKICAgICAgICBmZmx1c2goc3RkaW4pOwoKICAgICAgICBpZiAoY29uc3VtaWRvcltpXS5jb2RUQyA9PSAxKSB7CiAgICAgICAgICAgIHByaW50ZigiXG5SZXNpZGVuY2lhbCIpOwogICAgICAgICAgICBwcmludGYoIlxuXG5EaWdpdGUgbyBudW1lcm8gZG8gY29uc3VtaWRvcjogIik7CiAgICAgICAgICAgIHNjYW5mKCIlaSIsICZjb25zdW1pZG9yW2ldLm51bSk7CiAgICAgICAgICAgIHByaW50ZigiXG5EaWdpdGUgYSBxdWFudGlkYWRlIGRlIGtXaCBjb25zdW1pZG9zIGR1cmFudGUgbyBtZXM6ICIpOwogICAgICAgICAgICBzY2FuZigiJWYiLCAmY29uc3VtaWRvcltpXS5rd2gpOwogICAgICAgICAgICAvL08gdG90YWwgZG8gdmFsb3Igc2VtIHRhcmlmYSwgb3Ugc2VqYSBvIGN1c3RvIHRvdGFsIHBhcmEgY2FkYSBjb25zdW1pZG9yOwogICAgICAgICAgICB0b3RhbCA9IGNvbnN1bWlkb3JbaV0ua3doICogMC4zOwogICAgICAgICAgICAvL08gdG90YWwgZG8gdmFsb3IgY29tIHRhcmlmYSwgb3Ugc2VqYSBvIHRvdGFsICsgdGFyaWZhcwogICAgICAgICAgICB0b3RhbFQgPSB0b3RhbCArIDUuMTc7CiAgICAgICAgICAgIGNvbnN1bW8xID0gY29uc3VtaWRvcltpXS5rd2g7CiAgICAgICAgfSBlbHNlIGlmIChjb25zdW1pZG9yW2ldLmNvZFRDID09IDIpIHsKICAgICAgICAgICAgcHJpbnRmKCJcbkNvbWVyY2lhbCIpOwogICAgICAgICAgICBwcmludGYoIlxuXG5EaWdpdGUgbyBudW1lcm8gZG8gY29uc3VtaWRvcjogIik7CiAgICAgICAgICAgIHNjYW5mKCIlaSIsICZjb25zdW1pZG9yW2ldLm51bSk7CiAgICAgICAgICAgIHByaW50ZigiXG5EaWdpdGUgYSBxdWFudGlkYWRlIGRlIGtXaCBjb25zdW1pZG9zIGR1cmFudGUgbyBtZXM6ICIpOwogICAgICAgICAgICBzY2FuZigiJWYiLCAmY29uc3VtaWRvcltpXS5rd2gpOwogICAgICAgICAgICB0b3RhbCA9IGNvbnN1bWlkb3JbaV0ua3doICogMC41OwogICAgICAgICAgICAvL08gdG90YWwgZG8gdmFsb3IgY29tIHRhcmlmYSwgb3Ugc2VqYSBvIHRvdGFsICsgdGFyaWZhcwogICAgICAgICAgICB0b3RhbFQgPSB0b3RhbCArIDUuMTc7CiAgICAgICAgICAgIGNvbnN1bW8yID0gY29uc3VtaWRvcltpXS5rd2g7CiAgICAgICAgfSBlbHNlIGlmIChjb25zdW1pZG9yW2ldLmNvZFRDID09IDMpIHsKICAgICAgICAgICAgcHJpbnRmKCJcbkluZHVzdHJpYWwiKTsKICAgICAgICAgICAgcHJpbnRmKCJcblxuRGlnaXRlIG8gbnVtZXJvIGRvIGNvbnN1bWlkb3I6ICIpOwogICAgICAgICAgICBzY2FuZigiJWkiLCAmY29uc3VtaWRvcltpXS5udW0pOwogICAgICAgICAgICBwcmludGYoIlxuRGlnaXRlIGEgcXVhbnRpZGFkZSBkZSBrV2ggY29uc3VtaWRvcyBkdXJhbnRlIG8gbWVzOiAiKTsKICAgICAgICAgICAgc2NhbmYoIiVmIiwgJmNvbnN1bWlkb3JbaV0ua3doKTsKICAgICAgICAgICAgdG90YWwgPSBjb25zdW1pZG9yW2ldLmt3aCAqIDAuNzsKICAgICAgICAgICAgLy9PIHRvdGFsIGRvIHZhbG9yIGNvbSB0YXJpZmEsIG91IHNlamEgbyB0b3RhbCArIHRhcmlmYXMKICAgICAgICAgICAgdG90YWxUID0gdG90YWwgKyA1LjE3OwogICAgICAgIH0KICAgICAgICBtZWRpYSA9IGNvbnN1bW8xICsgY29uc3VtbzIgLyAyOwogICAgICAgIHByaW50ZigiXG5PIHRvdGFsIGRlIGNvbnN1bW8gZSAlLjJmXG4iLCB0b3RhbCk7CiAgICAgICAgcHJpbnRmKCJcbk8gY3VzdG8gdG90YWwgZSAlLjJmXG4iLCB0b3RhbFQpOwogICAgICAgIHByaW50ZigiXG5BIG1lZGlhIGRlIGNvbnN1bW8gZG9zIGNvbnN1bWlkb3JlcyAxIGUgMiBlICUuMmZcbiIsIG1lZGlhKTsKICAgICAgICBpKys7CiAgICB9IHdoaWxlKGNvbnN1bWlkb3JbaSAtIDFdLm51bSAhPSAwKTsKICAgIHJldHVybigwKTsKfQ==