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
qt
events
generics
weblogic12c
schema.org
plpgsql
adobe
vsts-build
ontology
linker
stored-procedures
position
wagtail
tiff
pushdown-automaton
dhcp
corona
global-variables
supervisord
google-cloud-logging
pfobject
node-webkit
eclipse-emf
ratio
onchange
django-import-export
monitor
instructions
john-the-ripper
variable-variables
uipickerview
newtons-method
system-on-chip
vb.net-to-c#
viewcontroller
angular-datatables
expandablelistview
docker-ucp
intellij-lombok-plugin
windows-media-player
cloudwatch
sony-future-lab-n
beeline
sharpdx
winmerge
clrs
degrees
front-camera
haraka
nclam
adjacency-list
distributed-cache
onepage-checkout
linuxbrew
dsa
jnlp
supercomputers
domino-designer-eclipse
ocmockito
shoes
nsmutabledata
nanomsg
oracle-adf-mobile
ecos
accessory
cidr
mod-perl
revmob
stty
xmlwriter
thejit
qtextbrowser
getopts
canonicalization
kohana-auth
django-pagination
libxslt
turbine
downgrade
pinax
.net-services
ppc
source-code-protection
subtext
jboss-mdb
rendering-engine
synthesizer

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile