944,030 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5150
  • C++ RSS
Apr 28th, 2007
0

select sort using array of pointers---getting wrong values.

Expand Post »
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.
Attached Files
File Type: doc coding.doc (24.0 KB, 117 views)
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
C++freak is offline Offline
4 posts
since Apr 2007
Apr 28th, 2007
0

Re: select sort using array of pointers---getting wrong values.

Why would I bother downloading your attachment. Post here and use code tags.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Apr 28th, 2007
0

Re: select sort using array of pointers---getting wrong values.

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.

  1. int main()
  2. {
  3. int numScores;
  4. int tests[numScores];
  5. cout << "Enter the number of test scores:";
  6. cin >> numScores;
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Apr 28th, 2007
0

Re: select sort using array of pointers---getting wrong values.

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.

  1. int main()
  2. {
  3. int numScores;
  4. int tests[numScores];
  5. cout << "Enter the number of test scores:";
  6. 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.
Reputation Points: 9
Solved Threads: 0
Newbie Poster
C++freak is offline Offline
4 posts
since Apr 2007
Apr 28th, 2007
0

Re: select sort using array of pointers---getting wrong values.

>>Can anyone please resolve this.
not if you don't give us current, compilable code. No point wasting our time on old obsolete code.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help!
Next Thread in C++ Forum Timeline: Solutions and Projects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC