I really need to do this program,
so I need ALOT of help.

I want the program to output a question asking "Enter John Smith's Bowling Score: ",
and that repeated abotu 20 times with Different names. (DO I need to store the names? if so, how?)

What the user inputs,
I want stored as the "score" for that specific bowler,
which I then need to be sorted in ascending order, and then displayed.

When displayed, I need the names to display WITH his/her scores next to it.

From what I know,
I'd need to make 2 One-dimensional arrays, one to store the names and one to store the scores. Then use a bubble sort to sort the scores.

But I really wouldn't know what-goes-where and how to put it all together.

can somebody send me links/information/codes to help me out with this?

You probably want something like:-

string array[20];
int score[20]

Then use cin or cin.getline to get the user enter the names/scores.

Sounds good.


But, how do I get the integer(that the user has inputted) to stay connected/matched with the string? & I dont want the user to have to enter the names, I want it to already be there.

When I sort it,
I dont want the bowler's to have somebody else's scores. Make sense?

You're probably using it as a parallel array.

So as you sort one array you make a note of their indexes and change the other array so it matches.

I don't know if this is too much help but it feels like it...

Anyway have a look at the code below:

(untested by the way)

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string names[3] = {"John","Anne","Mary"};
  int score[3] = {5,1,2};

  //i.e
  //John's score = 5
  //Anne's score = 1
  //Mary's score = 2
  
  //sort by score
  for ( int i = 0; i < 3; i++ )
  {
    for ( int j = 0; j < 3; j++ )
    {
      if( score[i] < score[j] )
      {
         string tmp_string;
         int temp;

         temp = score[i];  
         tmp_string = names[i]; //now swap the names array


         score[i] = score[j]; 
         names[i] = names[j]; //now swap the names array

         score[j] = temp;
         names[j] = tmp_string; //now swap the names array
      }
    }
  }

  //show them sorted
  cout << "Sorting by score in ascending order\n";
  for ( int k = 0; k < 3; k++ )
  {
    cout << "name:" << names[k] << " score:" << score[k] <<endl;
  }
  return 0;
}

It sorts by scores keeping the names together. In order to change it to sort by name instead all you have to do is change the line: if( score[i] < score[j] ) to if( names[i] < names[j] ) .

You should probably just create a struct that stores the name of the person and their score. Then store the the bowler struct in a vector.

This article has been dead for over six months. Start a new discussion instead.