10 grade input to output as entered.

I have an assignment to let a user input 10 test grades and then have 3 sets of output. The first one should be the list as entered by the user, the second is ascending order and the third is in descending order.

I have the ascending and descending orders working, but for some reason I'm having a brain fart and no matter what I try, I cannot get the list to output as entered by the user for the first step.

Please refer to the line with the question marks for the code I can't figure out.

Thanks.

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
#include <iostream>
#include <conio.h>

using namespace std;
 
int main ()
{   
    int x;
    int grades [10], t;
        
        for (x=1; x<=10; x++)
        {
        cout << "Enter your test grade #" << x << ": ";
        cin >> grades[x];
        }
        for (x=1; x<=10; x++)
        {
                for (int y=1; y<10; y++)
                {
                        if(grades[y]>grades[y+1])
                        {
                t=grades[y];
                grades[y]=grades[y+1];
                grades[y+1]=t;
                        }
                }
        }
        cout << endl << endl;

        cout << "The grades you entered are:\n";
        cout << "---------------------------\n";
             cout << grades[x]; //??????????????
             
        cout << endl << endl;
        
        cout << "The grades in ascending order are:\n";
        cout << "----------------------------------\n";
             for (x=1;x<=10;x++)
             { 
               cout << grades[x] << "  ";
             }
    
        cout << endl << endl;
 
        cout << "The grades in descending order are:\n";
        cout << "-----------------------------------\n";
             for (x=10;x>=1;x--)
             { 
               cout << grades[x] << "  ";
             }
             cout << endl;
        cout << endl;
        system ("PAUSE");
        return 0; 
        }
This code snip

1
2
3
4
5
6
7
    int grades [10], t;
        
        for (x=1; x<=10; x++)
        {
        cout << "Enter your test grade #" << x << ": ";
        cin >> grades[x];
        }


is already invalid because element subscriptors of an array of size N are in the range [0, N-1}
Last edited on
Okay, so what do I need to do to fix it and make it work? I have no clue.
I still need help with this, does anyone know what I need to do??
bumping this to the top, still looking for help on this, anything constructive would be appreciated. I don't know what vlad means in his post above.

Thanks,
Drew
Topic archived. No new replies allowed.