Question: I got an university task which i am totally stuck on. Normally I wouldn't post about it here, but none of my colleagues has any idea how to solve it.
The Task:

Design an algorithm "NEXT", which delivers the subsequent value of the numeric sequence {0,3,5,6,9,10,12,15,18,20,21,...} as function value whenever it is called. The algorithm must not use parameters or global variables or vectors.

I have to implement it in C++ (which shouldn't be too much of an issue for me). I just have no idea how. I can't find any form of rule for the number sequence. And i am kinda stuck on the part where i have to return the next value of the sequence without giving any parameters to the function.

It would be awesome if someone could help me out here :)

(FYI, i had to translate the task and i hope I didn't make any critical Errors... Here it is again in the original languge german:
Entwerfen Sie einen Algorithmus N E X T, der bei jedem Aufruf den
jeweils nachsten Wert der Folge {0,3,5,6,9,10,12,15,18,20,21,...} als Funktionswert liefert.
Der Algorithmus darf weder Parameter haben noch globale Variablen oder Vektoren verwenden.)

Answer: 
See below for the initial version of this answer. Though, rici made me realize that I made a mistake, probably the same mistake you made: I interpreted the task to write a plain function. However, being asked to write an algorithm does not mean that it must be a plain function only. Even if you want to write something that can be called, callables can have state. And if the callable is not a plain function then there are solutions that are much cleaner than a function local static variable as it was my first idea when writing this answer initially.

A callable can be a functor. An instance of a class with a call operator. I will stay with the initial example of a simple counter and leave the actual implementation of the algorithm to you:

```
#include <iostream>

struct counter {
    int value;
    int operator()() {
        ++value;
        return value;
    }
};

int main() {
    counter c1{};
    std::cout << c1() << "\n";
    std::cout << c1() << "\n";
    counter c2{42};
    std::cout << c2() << "\n";
    std::cout << c2() << "\n";
}

```

Compared to the function local static variable this has the benefit of being reusable. When you want to count again from the beginning you can create a fresh `counter`.

---

The initial version of the answer:

As mentioned in a comment, this task is probably meant to teach you about function local static variables. A simple example:

```
#include <iostream>

int count() { 
    static int i = 0;
    ++i;
    return i;
}

int main() {
    std::cout << count() << "\n";
    std::cout << count() << "\n";
    std::cout << count() << "\n";
}

```

`i` is initialized only on the first call and retains its value between function calls, ie the returned values differs by `1` for each call.

Whether function local static variables are any better than global variables in general is a matter of opinion. They make the function useable only for a specific scenario. Anyhow there are situations where a function local static variable is just the right tool so you should learn about them (but not confuse them with a goto solution for any case where a callable needs some state).
The sequence consists in all multiples of 3 or 5, in increasing order.