counting


Digit Counting Issue in C++ Program


I'm making a program that counts the amount of each number in a string of digits entered by the user. The result is the number of each digit from 0 to 9 in order showing how much of each was entered. For example, entering 575 would result in 0000020100. But for some reason, every time I run the program it thinks there's a number 8 somewhere. So instead I get 0000020110 for 575. Anyone know why this is happening?
#include <iostream>
using namespace std;
int main()
{
char x[80];
int dig, str, digcnt=0;
cout<<"Enter a number: ";
cin>>x;
for(dig=48;dig<58;dig++)
{
for(str=0;str<80;str++)
{
if((int)x[str]==dig)
digcnt++;
}
cout<<digcnt;
digcnt=0;
}
return 0;
}

Related Links

How to answer queries of type l,r,k which finds number of elements in an array in range l to r which occurs atleast k times?
Dafny and counting of occurences
Counting the number of capital letters in each row in [R]
python: count values of dictionary
How to apply hyperloglog to a timeseries stream
Counting the number of occurrences of C in each line and outputting this number plus the total number of characters in that line
Digit Counting Issue in C++ Program
Binary Strings of the form *111*

Categories

HOME
php
openshift
spring-data
powerbi
tomcat
windows-8.1
angular-ui-grid
seedstack
schema.org
devexpress
ews
semantic-web
material-components
javafx-8
yahoo
parsley.js
phpstorm-2017.1
circleci
tiff
orc
mailgun
playframework-2.0
clr
android-permissions
react-dnd
environment
managed-c++
web-config-transform
data-collection
ipa
history.js
dnsmasq
social-networking
copy-protection
om-next
gnu-classpath
directfb
android-canvas
rails-postgresql
transform
pdfminer
python-jira
contactless-smartcard
jqgrid-asp.net
morphline
type-inference
audio-converter
ssi
ol3-google-maps
scala-breeze
brightscript
nonlinear-functions
hibernate-ogm
embedded-v8
android-sharing
sequence-diagram
pen
deedle
mechanicalturk
instafeedjs
d3v4
gawk
streamwriter
jenkins-workflow
fiber
node.js-connect
qpixmap
jeasyui
i2b2
flush
flask-security
knife
espresso
search-form
quercus
prism-4
thoughtworks-go
symja
password-recovery
vs-unit-testing-framework
iodocs
distributed-r
preorder
pre
code39
rautomation
ember-table
ldif
nsmutablestring
android-dialog
glx
vows
dip
mongrel2
android-2.1-eclair
iphone-sdk-4.3
getimagesize
dm
gtktextview
ning
efs

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App