# Problem in my code

**URL:** https://discourse.julialang.org/t/problem-in-my-code/105021
**Category:** New to Julia
**Created:** [October 16, 2023, 3:15pm UTC](https://discourse.julialang.org/t/problem-in-my-code/105021 "2023-10-16T15:15:16Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 16, 2023, 3:31pm UTC](https://discourse.julialang.org/t/problem-in-my-code/105021/3 "2023-10-16T15:31:47Z")

</div>

To be even clearer:

```julia
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:

```julia
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:

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

```

---

_[View the full topic](https://discourse.julialang.org/t/problem-in-my-code/105021)._
