hi guys I have this few line,
nombreDePyramides = 4
var maxLignes: int = ((nombreDePyramides+2)*(nombreDePyramides+3)/2-4)
here the second line is giving me a float but I need a int because of the rest of the code and I can't find the syntax ...
-Pro-de-Pablo:sastentua pablocolson$ nim c satstentua.nim
Hint: used config file '/Users/pablocolson/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: satstentua [Processing]
satstentua.nim(2, 68) Error: type mismatch: got (float) but expected 'int'
MacBook-Pro-de-Pablo:sastentua pablocolson$
thanks for awnsers
This happens because / on ints returns a float. You want to use div instead, which is integer division.
var maxLignes = ((nombreDePyramides + 2) * (nombreDePyramides + 3)) div 2 - 4
Or, alternatively, convert it – this is clearly the inferior solution, but given here for completeness:
var maxLignes = int((nombreDePyramides+2)*(nombreDePyramides+3)/2-4)
In both cases, you do not need to give the type because it is derived from the expression.