Hello people, now I'm learning array.
I now know how to count integers with while loop
but I'm not sure how to count the integers with array.
so the question is:
1. program should keep reading integers as long as the integers are within [0,9999]
2. when user typed the integer not between 0 to 9999, the program print out the numbers of integers that were typed.
Sample
3
3
3
9999
9999
-1
You entered 3 3 times.
You entered 9999 2 times.
Can anyone help me with this, I think it is really simple, but I'm stuck from the beggining
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
usingnamespace std;
int main () {
int numbers[10000];
int i;
int n;
for (i = 0; i >= 0; i = i+1){
cin >> numbers[i];
}
for (
cout << "You entered " << i << " " << n << " times.\n";
return 0;
}
I think you should use two arrays. One that stores the numbers from 0 - 9999 in one array and the second that stores the numbers of times a certain number from the array is chosen.
I'm thinking that the user input should be in a while loop - - - you don't know how many times they are going to enter numbers right?
Running a for loop to initialize an array of all possible values could be done with the for loop you have but without the cin - that would mandate that someone enter 10000 values by hand. I don't think you need to do that though.
I think you can just do this with one array with 10000 elements (initialized to 0), and then increment the value of the element corresponding to the number entered by the user, e.g. if they enter 2000, array[2000] gets incremented by 1.