lines 17 to 21 won't put anything in the first position in the array. Arrays start at zero, Get used to doing this:
1 2 3 4 5
|
for(int i = 0; i < 5; i++){
do {
cout << "\n\nPlease enter a score: ";
cin >> scores[i];
} while(scores[i] < 0 || scores[i] > 100);
|
With line 30, use a for loop to do that. What if you had 1000 numbers?
lines 24 to 26 should be in a swap function, although you will have to name it something else, because there is already a
std::swap
. This can be a problem because of line 7. You are better off without line 7, and put
std::
before each std thing.
Sorting at the same time as input is bound to cause problems - have another for loop to do the sorting after input is finished.
For sorting the subscripts should be i and i-1, not 0. At the moment you are overwriting your data.
On line 11, rather than have the magic number 5, which appears in multiple places, declare the array size as a const:
const int SIZE = 5;
Then use the variable SIZE wherever the 5 appears. This way if you want to change the size, you can change it in 1 place only.
With the command line arguments, you need to do something similar to what
Smac89 had (are you allowed to use classes?), but reference the argv array. You teachers must have shown how to do that if it is a requirement of the assignment.
Also, my earlier advice - sounds boring but it works:
TheIdeasMan wrote:
Try writing psuedo code, start with general ideas of what you want to do in order. Keep going back and refine these ideas into more & more into detailed tasks. Write all these as comments in your .cpp file, leave the comments there, as they serve as documentation. When you are happy translate your comments into code.
This approach will help organise your thoughts, identify what should be in a function, switch etc. |
With compiling, use the maximum warning level:
or even -Werror which promotes warnings to errors.
Hope all goes well.