Garbage output

for some reason, count1 and count2 give me random numbers rather than the correct numbers. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
#include <iostream>

using namespace std;

int main()
{
    const int ans = 15;
    char Correct_grades [ans] {'A', 'A', 'B', 'C', 'D', 'C', 'D', 'C', 'A', 'B', 'A', 'B', 'C', 'C'};
    char grades [ans];


    cout<<"Please enter a letter between A - D"<<endl;

     int count = 0; //count how many elements are equal
     int count2 =0;

    for(int i = 1; i<ans; i++)
    {
        cin>>grades[i];


        for(int i = 1; i<=15; i++)
        {
            if(grades[i] == Correct_grades[i])
			count++;

			if(grades[i] != Correct_grades[i])
			count2++;

        }
    }



	cout<<"You have "<<count<<" correct."<<endl;

	cout<<"You have "<<count2<<" incorrect."<<endl;

	if (count >= 10)
        cout<<"You Passed"<<endl;
    else
        cout<<"You failed"<<endl;

/*
Store the correct answers to the questions in a character array of size 15.  Let the user enter answers for each of the 15 questions and store the answers in a separate array of size 15.
Your program should only accept A, B, C, D as answers.  After the answers are entered, the program should tally up the total number of correctly answered questions,
'
the total number of incorrectly answered questions and a list showing the questions that were answered incorrectly.
The user passed the test if they answered at least 10 of the questions correctly.  Print a message that says You passed if the user passed or You failed if the user failed the exam.
*/


    return 0;
}


you have a loop inside a loop and it's not counting correctly. So it's a logic problem.

how would you do this on paper, this transfer that to code.
Registered users can post here. Sign in or register to post.