User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,932 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,638 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 508 | Replies: 5
Reply
Join Date: Sep 2007
Posts: 37
Reputation: annagraphicart is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
annagraphicart annagraphicart is offline Offline
Light Poster

Question Sorting/assigning Help Needed Immediately

  #1  
Sep 10th, 2007
Hey guys, I'm in a bowling league and I need to code a program to help sort/assign points to the scores.
I do web design/graphic design
so if anybody can help me at all I will be glad to help any of you with any web/graphic needs.


Lets say theres 5 bowlers,
I need to have 5 separate
cout << "John Smith: "; (where the user will enter the score for each bowler separately)

then after all the scores have been inputted, I need the program to have it sorted ascending.

LASTLY, I need "points" to be assigned.

If there are 5 bowlers, the highest score gets 5 points,
then the 4th bowler gets 4, etc, etc.
But if the score is 0, then they get 0 points.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,166
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 930
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: Sorting/assigning Help Needed Immediately

  #2  
Sep 10th, 2007
I would use a structure to hold the information for each bowler, then after entering the information sort the array of structures by score. After that print the array information.
struct bowler
{
    std::string bowlername;
    int score;
    int points;
};
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Sep 2007
Posts: 37
Reputation: annagraphicart is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
annagraphicart annagraphicart is offline Offline
Light Poster

Re: Sorting/assigning Help Needed Immediately

  #3  
Sep 10th, 2007
Originally Posted by Ancient Dragon View Post
I would use a structure to hold the information for each bowler, then after entering the information sort the array of structures by score. After that print the array information.
struct bowler
{
    std::string bowlername;
    int score;
    int points;
};


Well.. I wouldn't know how to do the rest then....
how do I get the program to sort the scores and then automatically assign points accordingly to the rank?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,324
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Sorting/assigning Help Needed Immediately

  #4  
Sep 10th, 2007
>Well.. I wouldn't know how to do the rest then....
Well, let's start over. What do you know? We're not mindreaders, so there's no way to tell how much hand holding you need or expect.

>how do I get the program to sort the scores
Oddly enough, C++ has a function called std::sort.

>then automatically assign points accordingly to the rank?
Well, it sounds like you want points to match the index of the sorted array, so I would make an educated guess that it's quite trivial to assign the points once you've sorted the array:
for ( int i = 0; i < n; i++ ) {
  if ( bowler[i].score == 0 )
    bowler[i].points = 0;
  else
    bowler[i].points = i + 1;
}
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Sep 2007
Posts: 37
Reputation: annagraphicart is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
annagraphicart annagraphicart is offline Offline
Light Poster

Re: Sorting/assigning Help Needed Immediately

  #5  
Sep 10th, 2007
Originally Posted by Narue View Post
>Well.. I wouldn't know how to do the rest then....
Well, let's start over. What do you know? We're not mindreaders, so there's no way to tell how much hand holding you need or expect.

>how do I get the program to sort the scores
Oddly enough, C++ has a function called std::sort.

>then automatically assign points accordingly to the rank?
Well, it sounds like you want points to match the index of the sorted array, so I would make an educated guess that it's quite trivial to assign the points once you've sorted the array:
for ( int i = 0; i < n; i++ ) {
  if ( bowler[i].score == 0 )
    bowler[i].points = 0;
  else
    bowler[i].points = i + 1;
}




Okay so I know the basic C++ stuff. Simple Input/processing/Output stuff.

From what I know I'll do this
int main ()
{
//Input
cout << "Enter John Smith's Score: ";
cin >> johnsmith;
cout << "Enter Jane Doe's Score: ";
cin >> janedoe;

Then its the processing that I dont know what to do.
That code you sent me,
Is that all I put in the processing?
I mean.. What does the "i" and the "n" and the "++" represent??


I'm sorry for being such an amateur, it must be annoying.
i'm trying my hardest, but at this point I think i just need somebody with more knowledge to help me.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,166
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 930
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: Sorting/assigning Help Needed Immediately

  #6  
Sep 10th, 2007
>>What does the "i" and the "n" and the "++" represent??

>>Okay so I know the basic C++ stuff

If you new the basic c++ stuff you would not need to ask that question. So I suggest you go back and re-read your text book, and read it as often as necessary until you have a good handle on the basics. I nearly wore the pages of my book out during my first year of programming.

The ++ is a shorthand operator to increment a variable and is the same thing as i = i + 1;
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC