I am learning Ocaml and as part of an exercise, I have to create a function that returns the following day of a couple (day, month, year).
I did the function, but the software that evaluates my code tells me I'm using too much if ... then ... else ... I haven't found a solution for several hours. Can someone help me ?
let leap = fun x -> x mod 4 = 0 && x mod 100 <> 0 || x mod 400 = 0
let nbDay(month,year) = match monthwith
| 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31
| 4 | 6 | 9 | 11 -> 30
| 2 -> if(leap(year)) then 29 else 28
| _ -> 0
let valid (day, month, year) = day <= nbDay(month,year)
&& day>= 1
&& month<=12
&& month>= 1
let tomorrow (day, month, year) = if(valid (day, month, year))
then if(day= nbDay(month,year))
then
if(month= 12)
then
let day= 1 in
let month= 1 in
let year= year+ 1 in
(day, month, year)
else
let day= 1 in
let month= month+ 1 in
(day, month, year)
else
let day= day+ 1 in
(day, month, year)
else failwith "invalid date!"