# Problem in my code

To be even clearer:

``````nouvelles_infections = Int[susceptibles[jour - 1] * taux_transmission * infectes[jour - 1] / population_totale]
``````

Here you are saying the number of new infections is given by the number of susceptible agents in the population yesterday, multiplied by a transmission rate and the share of infected in the total population. Clearly it is unlikely that this number will be an integer - the transmission rate is probably not an exact integer, and neither will the share of infected in the total population be. So this calculation is bound to create a non-integer number; if you want the number to be integer you have to round it explicitly, so:

``````nouvelles_infections = round(Int, susceptibles[jour - 1] * taux_transmission * infectes[jour - 1] / population_totale)
``````

Note here I’ve replaced `Int[...]` with `round(Int, ...)`. This will give a single integer number which is then assigned to `nouvelles_infections`. It’s not clear to me why you are doing `Int[...]` here but note that this creates an array of integers with a single number in it, which is not the same as just the number. Later on you are doing:

``````push!(susceptibles, susceptibles[jour - 1] - nouvelles_infections)
``````

which suggests that `susceptibles` is a vector that you are using to track the number of not-yet-infected over time. Then `susceptibles[jour-1]` is an element of that vector, i.e. likely a single integer, which means `susceptibles[jour - 1] - nouvelles_infections` will fail if `nouvelles_infections` is an array rather than an integer:

``````julia> 4 - [2]
ERROR: MethodError: no method matching -(::Int64, ::Vector{Int64})
For element-wise subtraction, use broadcasting with dot syntax: scalar .- array
``````
1 Like