To gamehead200 Quote:
Originally posted by gamehead200 Because I'm nice and its due tomorrow, here's part of my code: Code: while( i < sent.size() )
{
switch( sent[ i ] )
{
case 'a':
acount++;
break;
}
i++;
} And to only show the letters that actually appear more than 0 times: Code: if( acount )
cout << "a = " << acount << endl; |
Hey gamehead, it's a good start.
However, you need a long switch statement and lots of variables. Here is a global solution if you like to move on with coding:
1)Try to decouple things.
Basically ask yourself:
What if I change one critical thing, how bad do other parts will perform because they depend on it? Can I make it so other parts don't (or almost don't) depend on it?
2)Make sure you know what you want:
Ask yourself:
This is how my function look. But is this function really responsible for so many things?
Look at my code and observe
void count_chars().
It does strictly the calculating. Nothing else at all.
While the menu-function is strictly responsible for setting up a menu and processing and validating input.
Actually, the latter is too much already!!! But you're not ready for that yet. Just a heads up though.
And finally the print function. It has some "smartness" in it, the code is so small, I made it part of the function. But I'm moving on the edge already.
Let these two things be your guide next time.