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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 4
Reputation: C++freak is an unknown quantity at this point 
Solved Threads: 0
C++freak C++freak is offline Offline
Newbie Poster

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

 
0
  #1
Apr 28th, 2007
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, 12 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #2
Apr 28th, 2007
Why would I bother downloading your attachment. Post here and use code tags.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #3
Apr 28th, 2007
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;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 4
Reputation: C++freak is an unknown quantity at this point 
Solved Threads: 0
C++freak C++freak is offline Offline
Newbie Poster

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

 
0
  #4
Apr 28th, 2007
Originally Posted by Ancient Dragon View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #5
Apr 28th, 2007
>>Can anyone please resolve this.
not if you don't give us current, compilable code. No point wasting our time on old obsolete code.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC