bonjour,

Le problème est le suivant : au calcul des ratio, je peux obtenir des nombre réels donc j'ai déclaré en float la struture cependant en faisant un printf je m'aperçois que ceux qui devraient être réels sont en fait entiers alors que 1,5 n'est pas entier ! Je ne vois pas d'où cela vient !


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
struct cout_fer
{
       float astroport;
       float faculte;
       float centre_bancaire;
       float cente_experts;
       float gestion_batiments;
       float gestion_ressources;
       float gestion_unite;
       float terminal;
       float mine_fer;
       float mine_carbone;
       float mine_or;
       float usine_armement;
       float usine_assemblage;
       float usine_recyclage;
       float hangar_blinde_carbone;
       float hangar_blinde_fer;
       float hangar_blinde_or;
       float hangar_blinde_robots;
       float hangar_blinde_armement;
       float crypto_modem;
       float teleporteur_batiments;
       float teleporteur_matiere;
       float teleporteur_unite;
       float vortex;
};
 
struct cout_carbone
{
       float astroport;
       float faculte;
       float centre_bancaire;
       float cente_experts;
       float gestion_batiments;
       float gestion_ressources;
       float gestion_unite;
       float terminal;
       float mine_fer;
       float mine_carbone;
       float mine_or;
       float usine_armement;
       float usine_assemblage;
       float usine_recyclage;
       float hangar_blinde_carbone;
       float hangar_blinde_fer;
       float hangar_blinde_or;
       float hangar_blinde_robots;
       float hangar_blinde_armement;
       float crypto_modem;
       float teleporteur_batiments;
       float teleporteur_matiere;
       float teleporteur_unite;
       float vortex;
};
 
struct cout_or
{
       float astroport;
       float faculte;
       float centre_bancaire;
       float cente_experts;
       float gestion_batiments;
       float gestion_ressources;
       float gestion_unite;
       float terminal;
       float mine_fer;
       float mine_carbone;
       float mine_or;
       float usine_armement;
       float usine_assemblage;
       float usine_recyclage;
       float hangar_blinde_carbone;
       float hangar_blinde_fer;
       float hangar_blinde_or;
       float hangar_blinde_robots;
       float hangar_blinde_armement;
       float crypto_modem;
       float teleporteur_batiments;
       float teleporteur_matiere;
       float teleporteur_unite;
       float vortex;
};
 
struct cout_credit
{
       float astroport;
       float faculte;
       float centre_bancaire;
       float cente_experts;
       float gestion_batiments;
       float gestion_ressources;
       float gestion_unite;
       float terminal;
       float mine_fer;
       float mine_carbone;
       float mine_or;
       float usine_armement;
       float usine_assemblage;
       float usine_recyclage;
       float hangar_blinde_carbone;
       float hangar_blinde_fer;
       float hangar_blinde_or;
       float hangar_blinde_robots;
       float hangar_blinde_armement;
       float crypto_modem;
       float teleporteur_batiments;
       float teleporteur_matiere;
       float teleporteur_unite;
       float vortex;
};
 
struct ratio_mine_fer
{
       float fer;
       float carbone;
       float or;
       float credit;
       float carburant;
};
 
 
int main(int argc, char *argv[])
{
 
    int lvl=12;
 
    struct cout_fer       *cout_fer;
    struct cout_carbone   *cout_carbone;
    struct cout_or        *cout_or;
    struct cout_credit    *cout_credit;
    struct ratio_mine_fer ratio_mine_fer;
 
    cout_fer     = malloc(  100*sizeof( struct cout_fer     )  );
    cout_carbone = malloc(  100*sizeof( struct cout_carbone )  );
    cout_or      = malloc(  100*sizeof( struct cout_or      )  );
    cout_credit  = malloc(  100*sizeof( struct cout_credit  )  );
 
    ratio_mine_fer.fer     = (30/20 );
    ratio_mine_fer.carbone = (137/90);
    ratio_mine_fer.or      = (67/44 );
    ratio_mine_fer.credit  = (8/5   );
 
    printf("%f\n%f\n%f\n%f\n" , ratio_mine_fer.fer ,ratio_mine_fer.carbone ,ratio_mine_fer.or ,ratio_mine_fer.credit );
 
    getch();
 
    cout_fer    [lvl].mine_fer = ( int )(  20*pow( ratio_mine_fer.fer     ,lvl-1 )  );
    cout_carbone[lvl].mine_fer = ( int )(  90*pow( ratio_mine_fer.carbone ,lvl-1 )  );
    cout_or     [lvl].mine_fer = ( int )(  44*pow( ratio_mine_fer.or      ,lvl-1 )  );
    cout_credit [lvl].mine_fer = ( int )(   5*pow( ratio_mine_fer.credit  ,lvl-1 )  );
 
    printf( "fer=%f\ncarbonne=%f\nor=%f\ncredit=%f ", cout_fer    [lvl].mine_fer
                                                    , cout_carbone[lvl].mine_fer
                                                    , cout_or     [lvl].mine_fer
                                                    , cout_credit [lvl].mine_fer );
 
    getch();
}

Merci