line 14 syntax error -- should end in comma not semicolon
line 19 syntax error -- int counts[9]{0} to initialize every index to 0.
Then I removed your cin.get() line near the end, and I finally got it to run:
The number 0 appears 0 time(s).
The number 1 appears 0 time(s).
The number 2 appears 0 time(s).
The number 3 appears 0 time(s).
The number 4 appears 0 time(s).
The number 5 appears 0 time(s).
The number 6 appears 0 time(s).
The number 7 appears 0 time(s).
The number 8 appears 0 time(s). |
You should be more descriptive in
what is wrong. JLBorges was just showing you that you don't need a triple loop -- a double nested loop is enough, and you should convert your code to not use three loops.
Edit: I see it.
counts[digit] = counts[digit]++;
This^ is logically wrong.
1. Your digit goes from 1 to 9, while your counts array only sets aside space for indices 0..8. So the first thing to change is to change that part to
counts[digit-1]
.
2. You used post-increment operator.
AFTER the assignment, the temporary (right of the equals sign) side gets incremented. You want either
1 2 3 4 5 6 7
|
counts[digit-1] = ++counts[digit-1];
//or
counts[digit-1] = counts[digit-1]+1;
//or
++counts[digit-1];
//or
counts[digit-1]++;
|
P.S. At the end, line 39, you want to display x+1, not x.
cout << "The number " << x+1 << " appears "