You need to create a For loop to loop 50 times, asking for a number each time, and storing that number in the array. Hint: you use the For loop variable to point to each index of your array as it loops.
In addition to what @Softrix suggested, you can also sort the numbers by implementing either bubblesort, insertion sort, or selection sort; or alternatively, you can just use the sort function in the algorithms library:
You want to report negative when grades[i] is less than 0, not the counter i is greater than 0.
Also, if you print grades[50], you are printing beyond the array by 1.
Possible example of a correctly implemented spoiler for your current available code:
http://pastie.org/9221020#7,11-12,14,17,24
If your code is confidential, you can use the, copy/repaste, button on the top right, editing it to have nothing, to removing its content - ideally (it is public).
Line 15 and 33 are not anywhere close to how you fill and print an array. Maybe in python, you can use list comprehension to fill an entire array with inputs from the user, but in c++ it is a bit different.
To fill the array with inputs from the user, you must make use of a for-loop. What's a for-loop you may ask? http://www.cplusplus.com/doc/tutorial/control/
Read the section called Iteration statements
sort (grades, grades+counter);//Ensures the array is sorted! default!
cout<<"Reporting after sort: "<<endl;
for(int i = 0; i< counter; i++)
{
//terminates data if negative numbers are entered.
if(grades[i] < 0)
{
invalid = true;
cout<<("Negative numbers are invalid.")<<endl;
return 0;
}
//Displays Array.
cout << grades[i] << "\t";
}
cout<<"\nReporting in large to small: "<<endl;//Modified print
for (int i = counter-1; i > -1; --i)//Counter comparison is 'i', not grades
{
//Displays Array.
cout << grades[i] << "\t";
}
Enter the grades:
5
2
6
3
7
4
1
a
Reporting after sort:
1 2 3 4 5 6 7
Reporting in large to small:
7 6 5 4 3 2 1
Press 'enter' to exit:
That is, if you wanted to print, in reverse order.
You could also achieve the result by sorting in the reverse order before a standard print:
//Function declarations:
bool isGreater(int i, int j){return (i>j);}
bool isLess(int i, int j){return (i<j);}
//Inside main:
sort (grades, grades+counter,isGreater);
cout<<"Reporting after sort: "<<endl;
for(int i = 0; i< counter; i++)
{
//terminates data if negative numbers are entered.
if(grades[i] < 0)
{
invalid = true;
cout<<("Negative numbers are invalid.")<<endl;
return 0;
}
//Displays Array.
cout << grades[i] << "\t";
}
cout<<"\nReporting in large to small: "<<endl;//A standard print.
for (int i = 0; i < counter; ++i)
{
//Displays Array.
cout << grades[i] << "\t";
}
Enter the grades:
5
2
6
3
7
4
1
a
Reporting after sort:
7 6 5 4 3 2 1
Reporting in large to small:
7 6 5 4 3 2 1
Press 'enter' to exit:
Advice: do not call sort multiple times, simply to change how output is displayed. Manipulating display procedures can be less expensive than forcing a sort and a display; normally.