This should display 5 lines of code that say "test", yet I am only getting 4 and it is never reaching zero, since the output never displays, "the test is over". What is wrong with this implementation? I am quite sure it's an error in my next() function.
Any help would be great.
Thanks in advance!
#include <iostream>
#include <cassert>
using namespace std;
class CountDown
{
public: //Application Programmer Interface
CountDown(int start); // it is set to start
void next(); // subtracts one from it
bool end()const; //
private:
int it;
};
CountDown::CountDown(int start)
{
it = 0;
it = start;
}
void CountDown::next()
{
it = it - 1;
}
bool CountDown::end() const
{
if (it <= 0)
cout << "The countdown is now over" << endl;
}
int main()
{
for( CountDown i = 5 ; ! i.end(); i.next())
std::cerr << "test\n";
}