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";

}

CountDown::end() doesn't return anything yet you declared it to return bool. That makes you a liar. ;)

#
for( CountDown i = 5 ; ! i.end(); i.next())
#
std::cerr << "test\n";

CountDown::end() function checks if it has reached 0 but not returns a boolean value. You must return true if it is zero in order to use it with the for loop above.

== nevermind ==

Lol gotta love geek humor, pretty sad I even laugh at myself when I find myself in a bad case of mislogicitus.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.