~eaglescreen/ple/2010-2011

« back to all changes in this revision

Viewing changes to BELMONTE RAFAEL 2da EVALUACION/Examen marzo 2011/01_factura_electrica.c

  • Committer: Rafael Belmonte
  • Date: 2011-03-27 13:37:36 UTC
  • Revision ID: eaglescreen@gmail.com-20110327133736-3ooxj7qs93rl5779
Ficheros; atou, MiStricmp; uconio.c:cgets mejorada

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
150 abonados
 
3
 
 
4
Los primeros 240 a 2€ los kwh
 
5
Los siguientes 300 a 1.5€ el kwh
 
6
por encima de 540 a 1.0€ el kwh
 
7
 
 
8
LIMITE1 240
 
9
LIMITE2 540
 
10
 
 
11
El consumo se calcula como el consumo el consumo actual - consumo anterior.
 
12
 
 
13
De 0 a 240 kwh (2.0€ kwh) = 480€
 
14
De 241 a 540 kwh (1.5€ kwh) = 450€
 
15
De 0 a 541 kwh (1.0€ kwh) = 1400€
 
16
-------------------------------------
 
17
TOTAL FACTURA ............... = 2330€
 
18
***************************************************************************/
 
19
 
 
20
#include <stdio.h>
 
21
 
 
22
#define TAR1 2.0
 
23
#define TAR2 1.5
 
24
#define TAR3 1.0
 
25
#define LIM1 240.0
 
26
#define LIM2 540.0
 
27
#define N_ABONADOS 3
 
28
 
 
29
typedef struct
 
30
{
 
31
  float consumo;
 
32
        float p1;
 
33
        float p2;
 
34
        float p3;
 
35
        float total;
 
36
} PRECIOS;
 
37
 
 
38
int ch;
 
39
float PedirDatos(void);
 
40
PRECIOS CalculaGastos(float);
 
41
void LineasFactura(PRECIOS);
 
42
 
 
43
int main()
 
44
{
 
45
  PRECIOS importe;
 
46
        unsigned i;
 
47
        for(i=0;i<N_ABONADOS;i++)
 
48
        {
 
49
                importe=CalculaGastos(PedirDatos());
 
50
                LineasFactura(importe);
 
51
  }
 
52
  while((ch=getchar())!='\n');
 
53
      ch=getchar();
 
54
  return 0;
 
55
}
 
56
float PedirDatos()
 
57
{
 
58
        float act, ant;
 
59
        printf("Introduzca el consumo actual: \n>");
 
60
        scanf("%f",&act);
 
61
        printf("Introduzca el consumo anterior: \n>");
 
62
        scanf("%f",&ant);
 
63
        return act-ant;
 
64
}
 
65
 
 
66
PRECIOS CalculaGastos(float consumo)
 
67
{
 
68
        PRECIOS precio;
 
69
        precio.p1=precio.p2=precio.p3=precio.total=precio.consumo=0;
 
70
        if (consumo<=LIM1)
 
71
                precio.p1=consumo*TAR1;
 
72
        else if (consumo > LIM1 && consumo < LIM2)
 
73
        {
 
74
       precio.p1=LIM1*TAR1;
 
75
       precio.p2=(consumo-LIM1)*TAR2;
 
76
  }
 
77
  else if (consumo > LIM2)
 
78
  {
 
79
       precio.p1=LIM1*TAR1;
 
80
       precio.p2=(LIM2-LIM1)*TAR2;
 
81
       precio.p3=(consumo-LIM2)*TAR3;
 
82
  }
 
83
  precio.total=precio.p1+precio.p2+precio.p3;
 
84
  precio.consumo=consumo;
 
85
  return precio;
 
86
}
 
87
 
 
88
void LineasFactura(PRECIOS importe)
 
89
{
 
90
     if (importe.consumo<LIM1)
 
91
     {
 
92
        printf("\nDe 0 a %.0f ( %.1f eur kwh ) = %.2f euros\n",importe.consumo,TAR1,importe.p1);
 
93
        printf("\nTOTAL: ............................ %.2f euros\n\n\n",importe.total);
 
94
     }
 
95
     if (importe.consumo>LIM1 && importe.consumo<LIM2)
 
96
     {
 
97
         printf("\nDe 0 a %.0f ( %.1f eur kwh ) = %.2f euros\n",LIM1,TAR1,importe.p1);
 
98
         printf("\nDe %.0f a %.0f ( %.1f eur kwh ) = %.2f euros\n",LIM1,importe.consumo,TAR2,importe.p2);
 
99
         printf("\nTOTAL: ............................ %.2f euros\n\n\n",importe.total);
 
100
     }
 
101
     if (importe.consumo>LIM2)
 
102
     {
 
103
      printf("\nDe 0 a %.0f ( %.1f eur kwh ) = %.2f euros\n",LIM1,TAR1,importe.p1);
 
104
      printf("\nDe %.0f a %.0f ( %.1f eur kwh ) = %.2f euros\n",LIM1,LIM2,TAR2,importe.p2);
 
105
      printf("\nDe %.0f a %.0f ( %.1f eur kwh ) = %.2f euros\n",LIM2,importe.consumo,TAR3,importe.p3);
 
106
      printf("\nTOTAL: ............................ %.2f euros\n\n\n",importe.total);
 
107
     }
 
108
}