Can you please help correct my code?
Here is the original problem.
All I need is help with the incrementation, I would really appreciate it.
My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to the store, if she bought all the items in her basket. There was a four digit display, increment buttons for each digit, and a reset button. There was an overflow indicator that came up red if more money was entered than the $99.99 it would register. (This was a long time ago).
Write and implement the member functions of a class "Counter" that simulates and slightly generalizes the behavior of this grocery store counter. The constructor should create a "Counter" object that can count up to the constructor's argument. That is, Counter(9999) should provide a counter that can count up to 9999. A newly constructed counter displays a reading of zero. the member function void reset(); sets the counter's number to 0. The member functions void incr1(); increments the units digits by 1, void incr10(); increments the tens digit by 1, and void incr100(); and void incr1000(); increment the next two digits respectively. Accounting for any carry when you increment should require no further action than adding an appropriate number to the private data member. A member function bool overflow(); detects overflow. (Overflaw is the result of incrementing the counter's private data member beyond the maximum entered at counter construction.)
Use this class to provide a simulation of the mother's little red clicker. Even though the display is an integer, in the simulation, the rightmost (lower-order) two digits are always thought of as cents, and tens of cents, the next digit is dollars, and the forth digit is tens of dollars.
Provide keys for cents, dimes, dollars, and tens of dollars. Unfortunately, no choice of keys seems particularly mnemonic. One choice is to use the keys asdf0: a for cents, followed by a digit 1 to 9; s for dimes, followed by a digit 1 to 9; d for dollars, followed by a digit 1 to 9; and f for tens of dollars, again followed by a digit 1 to 9. Each entry (one of asdf followed by 1 to 9) is followed by pressing the Return key. Any overflow is reported after each operation. Overflow can be requested by pressing the 0 key.
AND HERE IS MY CODE:
#include<iostream>
using namespace std;
class counter
{
public:
counter();
void reset();
void incr1();
void incr10();
void incr100();
void incr1000();
void displayunits();
void displaytens();
void displayhundreds();
void displaythousands();
int currentcount();
void display();
bool overflow();
private:
int units;
int tens;
int hundreds;
int thousands;
};
int main()
{
char ch;
counter c;
if(c.overflow())
cout<<"overflow"<<endl;
c.displaythousands();
c.displayhundreds();
cout<<".";
c.displaytens();
c.displayunits();
cout<<endl;
cout<<"Enter a character followed by a digit 1-9 "<<endl;
cout<<"Enter a for units"<<endl;
cout<<"s for tens"<<endl;
cout<<"d for hundreds"<<endl;
cout<<"f for thousands"<<endl;
cin>>ch;
cin>>j; //input number
switch(ch)
{
case 'a':
for(i=0;i<j;i++)
c.incr1();
break;
case 's':
for(i=0;i<j;i++)
c.incr10();
break;
case 'd':
for(i=0;i<j;i++)
c.incr100();
break;
case 'f':
for(i=0;i<j;i++)
c.incr1000();
break;
default:
exit(0);
}
}
return 0;
}
void counter::displayunits()
{
cout<<units;
}
void counter::displaytens()
{
cout<<tens;
}
void counter::displayhundreds()
{
cout<<hundreds;
}
void counter::displaythousands()
{
cout<<thousands;
}
void counter::reset()
{
units=tens=hundreds=thousands=0;
}
void counter::display()
{
cout<<thousands<<hundreds<<tens<<unit…
}
bool counter::overflow()
{
}
counter::counter():units(0),tens(0),hu…
{
}

