From the course: Introducing Functional Programming in C++

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Factorial continuous add

Solution: Factorial continuous add - C++ Tutorial

From the course: Introducing Functional Programming in C++

Start my 1-month free trial

Solution: Factorial continuous add

(electronic music) - [Instructor] My solution is somewhat similar to the incremental lambda we created earlier except it sets the initial value to the past initial argument and it adds the value of addBy instead of one each successive call. So let's take a look at it in code. Open up our main. We've already got our include file and our namespace. And right here we want to create auto space continuousAdd and the we have an open and closed square brace. We have our parenthesis. And we have an init integer. Initial comma integer addBy and then we're going to say that auto total equals initial. Now this step's probably not necessary but I like the purpose of all my variables to be very clear to me. Then we're going to say return. And then we want to capture total and addBy in our scope. Then we have take no variables here. And we're going to say that this is mutable. Because we're going to change the value of total. And then we're going to do a total plus equals addBy. And finally we'll…

Contents