### easy problem, but im a very beginner

first of all, im german so excuse my mistakes, if there are any :)

so i got to write a code where the user can put in grades, and the program can tell you the number for each grade, f.e:

Grades: 1 2 3 4 5 6

quantity: 2 3 6 3 4 1

I can do that all, it's not very hard, but my only problem is, how do i control, what the user put in?
my idea is, i have 6 variables and every time he inserts a 3, the variable for the number of 3's, counts one more.

here is the part of the code:

 ``123456789101112131415`` ``````int main() { int Anz1; int Anz2; int Anz3; int Anz4; int Anz5; cout>>"Bitte geben sie die Noten von 1 bis 5 ein, maximal 38 Noten.">> if ( "INPUT" == 1) { Anz1 + 1; }``````

What i only need to know is, what do i have to put in there, where "INPUT" stands yet. it's just a placeholder, because i dont know what to put there

we didnt learn it yet and i dont find any good suggestions.

help!

Last edited on
This looks like a good place to use a vector or an array to hold the "INPUT". Make sure you initialize each element of your container to zero. Then as you proceed use the "INPUT" as the index of your container to increment that element. You will need to first insure the INPUT is within the correct bounds ( it can't be less than zero and it can't be greater than the size of your container).
You can use an array of integers. For example

 ``1234567`` ``````const int N = 6; int grades]N]; for ( int i = 0; i < N; i++ ) { std::cin >> grades[i]; }``````
Topic archived. No new replies allowed.