>please help how can i do this
Two easy ways:Throw all of the numbers into a better suited data structure (such as an std::map).
Sort the array and do some counting.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Make an int array that has 10 elements (so you have one for each digit). Up the count in that "bin" when you encounter a particular digit. Output your array.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
but this is not working properly
That's ok because he/she probably shouldn't have given the whole thing away. Think about how else you might store a group of digits...
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Hint, don't take the digits in as numbers. Hold them in a char array or a string. Otherwise you can't hold spaces in an int array anyway.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
cin>>array[i]; remember that '\n' (like when you hit enter) is a character too. Look into using cin.getline() for this purpose to get the entire line of digits (up to the size of your char array).
-or-
Look into using getline(cin, ) with a std::string and you can avoid the size limitation.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Perhaps you did not get the message up there but please do NOT give the OP a full set of code. Help him or her through it but don't give the whole thing. This doesn't help him or her learn a thing.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Regardless, the general philosophy of this board is "we only give homework help to those who show effort" (meaning that the poster themselves should show the effort and receive help in proportion to their input).
Rather than writing the solution on your local machine and guiding this poster through it step by step you have handed him/her something that he/she could conceivably hand in for a grade. Trust me, darn near any experienced person could have done what you did for her and we didn't. There's a reason for that. The fact that you wanted to do it a second time after folks had expressed displeasure about it is kind of insulting.
Using your argument, I should never try to mix the colors myself because there is no value in that learning process. In doing so, again and again, you'll have to zip me through all the stages to get to the final product and then we can compare colors. I may know what the color looks like but I cannot get there on my own.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
s/he is using printf with using namespace std it just proves that s/he is beginner in these and s/he need to learn how to think in c/c++ to be able to solve task like these one and s/he wont learn that by reading some text but looking in code.
Jonsca is correct. You are mistaken.
If you want to show everyone your prowess at coding, give an illustrative piece of code they can learn from. Do NOT write the code for them.
After a whopping 10 posts, you do not yet have the creds to argue with a lowly "Nearly a Posting Virtuoso" (no disrespect intended, Jonsca).
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Why do you think it's homework may be s/he is just trying to learn something but don't have idea how to solve it.
- Instructors do not write the answers to homework problems on the board before giving out an assignment. Only after the assignment is done.
- Instructors frown upon copying answers from classmates preferring you to do your own work.
- Instructors frown upon students asking other students to do homework for them.
- Instructors generally don't mind if students help each other, short of turning in the exact same work
- Students are expected to do their own work and ask questions that help them understand the material.
- Plus more....
We are not their classmates. We therefore wish to abide by these expectations. They have been around for centuries. Who are you to say it's wrong?
... but sometimes you first need to see something from someone and than try yourself, at last it's just my opinion it doesn't have to be yours.
So give themsomething, just not the complete answer.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>s/he is using printf with using namespace std it just proves that s/he is beginner in these
There are experienced C++ programmers who prefer the stdio library over iostreams for various reasons.
>Why do you think it's homework may be s/he is just trying to
>learn something but don't have idea how to solve it.
That's certainly possible. However, due to the overwhelming number of students looking for a free ride, we prefer to assume that the question is homework and adjust our answers accordingly.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401