In c++ how do i make a function that figures out the most common occurence of a character in a string?
- VPLv 78 months ago
Well, that's what computer programming is all about. It's about solving problems (or puzzles, as I call 'em). It's not just about "writing code," like your buddies probably think. It's using your mind to creatively solve the problem at hand. And your problem is letting the user enter a random string (I'm guessing here), analyzing it, and telling the user certain things about the string they entered.
Very cool -- if you do it on your own. It's not hard, just grab some paper and a pencil, sit down and write something like:
"Four score and five years ago" at the top of the page (or for extra thoroughness: abcd efgbhijk lmnop qrstuv wxyz <-- yes, there are 2 b's). Then ask yourself how you'd MANUALLY figure out the most commonly occurring character. The rules are that you can only compare 2 things at one time; To "remember" something you have to put it into a bucket/box with a name (like a variable's name).
Pretend you're a computer doing one thing at a time and you should come up with a way to get the user's input, analyze it, then report on it.
Good luck! (and if you get stuck, show us how far you've gotten, tell us what's got you stuck, and we'll try to help!)
Hints: It would help to have learned about:
- converting chars either to all uppercase or all lowercase
- how to use IF statements
- finding the ASCII values of chars and vice-versa
- using loops (For loops, While/Do, Do/While, etc.)
- using strings or character arrays