Well, heres a code that I wrote that displays the number of letters in lower case of any sentence that I put into the program.

#include <iostream>
#include <string>

using namespace std;

int main()
{

int count[256] = { };
string str;
getline(cin,str);
for(string::iterator it = str.begin(); it != str.end(); ++it)
count[*it]++;
for(char ch='a'; ch <= 'z'; ++ch)
cout << ch << " - " << count[ch] << endl;
}

Could anyone help by telling me how I can add to it so it also counts upper case letters and also numbers 0-9? I am having so much trouble, and I left my Savitch book at my friends home :[

Thanks

Could anyone help by telling me how I can add to it so it also counts upper case letters and also numbers 0-9?

What does

for(char ch='a'; ch <= 'z'; ++ch)

do? Maybe something similar would work?

i think you can define the count array as 0 and then make a loop that displays every element of count with a value > 0

What does

for(char ch='a'; ch <= 'z'; ++ch)

do? Maybe something similar would work?

That displays the lower case letters in a sentence that is written in the buffer. I've tried the same thing in a loop with 'A' 'Z', but that doesn't work.

Then you did it wrong. And since you didn't bother to show is what you did do, there's not much to help with.

Then you did it wrong. And since you didn't bother to show is what you did do, there's not much to help with.

... You're serious? I showed you what I did. It would be nice if someone actually gave me ideas on how I could POSSIBLY get the program to output upper case and numbers. I don't know why you have to be a complete jack ass about it?

Of course I'm serious...

Where is your attempt at numbers and capital letters? It's identical in concept with what you have for lower case. If what you tried didn't work, post what you tried so we can help you fix it. Otherwise all you are asking is for us to do it for you.

We help you write your programs, we don't write it for you. And I've given you help. You have to show us why our help didn't work, not just claim it didn't.

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.