Dynamic programming and value-function approximation with application to optimal consumption