For some odd reason, I'm getting totally bogus answers (like answers in the 2 billions when it should output 2)
so I believe I'm initializing my term1 object correctly (initializing to 2) but I am obviously not getting it. Can someone please look this over and let me know what I'm doing wrong?! Thanks for the help!!!
Code:#include <iostream> #include <cstdlib> using namespace std; class CounterType { public: CounterType(int term); //Allows the user to change initial starting count in main() function. CounterType(); //Sets the counter to zero int term_up(); //Adds one to the count int term_down(); //Subtracts one from the count void display(ostream& show); //Displays results to the user private: int term; }; int main( ) { CounterType term1(2), term2; cout << "counter1 initialized as follows: " << endl; term1.display(cout); cout << "counter2 initialized as follows: " << endl; term2.display(cout); cin.get(); return 0; } int CounterType::term_up() { if (term < 0) { cout << "Illegal values for counter."; exit(1); } term = term++; } CounterType::CounterType(): term(0) { /* Left blank intentionally to reset value to 0*/ } int CounterType::term_down() { if (term < 0) { cout << "Illegal values for counter."; exit(1); } term = term--; } CounterType::CounterType(int count) { if (term < 0) { cout << "Illegal values for counter."; exit(1); } term = term; } void CounterType::display(ostream& show) { show << "Current value of the counter is: " << term << endl; }