Hi all,

I was writing a program for sorting the test scores using array of pointers and dynamic memory allocation. Surprisingly, I am getting indefinite values after sorting. I wrote a header file, .cpp file and main. cpp.
Actually, after sorting I thought of adding an average function in .cpp file and can call that function in main.
But first of all, I am unable to sort the test scores properly.
Can anybody tell me where I went wrong?
I am sending my code as attachment.

Thanks in advance.

Member Avatar for iamthwee

Why would I bother downloading your attachment. Post here and use code tags.

your program will not even compile correctly so why are you trying to run it. arrays can not be allocated the way you are attempting in line 4 below. You need to make variable tests a pointer and use new to allocate the memory after line 6, at which time the value of numScores will be known.

int main()
{
    int numScores;
    int tests[numScores];
    cout << "Enter the number of test scores:";
    cin >> numScores;

your program will not even compile correctly so why are you trying to run it. arrays can not be allocated the way you are attempting in line 4 below. You need to make variable tests a pointer and use new to allocate the memory after line 6, at which time the value of numScores will be known.

int main()
{
    int numScores;
    int tests[numScores];
    cout << "Enter the number of test scores:";
    cin >> numScores;

Thanks. I am sorry, while copying and pasting, it got missed int tests, but the program got compiled. While running, the problem starts.
Can anyone please resolve this.

>>Can anyone please resolve this.
not if you don't give us current, compilable code. No point wasting our time on old obsolete code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.