Take a look at the "points" section.
It says that i haven't declared the string name for "scores"... but scores is an int name not a string.

Whats going on?

#include <iostream> 
#include <string> 

using namespace std; 

int main()
{
      const int MAX=4;    
      std::string names1[4] = {"Anna" , "Jenny", "George" , "Michael"};   
      int score[4];
      string names2[4] = {"John Lennon", "Yoko Ono", "Jimi Hendrix", "Peter Frampton"};
      int score2[4];
      double points[4];

      cout << endl;
      cout << "ENTER SCORES FOR DIVISION 1" << endl << endl;

      for(int i = 0; i < 4; i++) 
      {   
            cout << names1[i] << ": ";     
            cin >> score[i];     
            cin.ignore(); 
            }

      cout << "ENTER SCORES FOR DIVISION 2" << endl << endl;

      for(int i = 0; i < 4; i++) 
      {   
            cout << names2[i] << ": ";     
            cin >> score2[i];     
            cin.ignore(); 
            }
            system("cls");

              //sort by score (div 1)  
              for ( int i = 0; i < 4; i++ )  
              { score[i];   
                    for ( int j = 0; j < 4; j++ )     
                    {       
                            if( score[i] > score[j] )       
                            {          
                                       string tmp_string;          
                                       int temp;           
                                       temp = score[i];            
                                       tmp_string = names1[i];           
                                       score[i] = score[j];           
                                       names1[i] = names1[j];           
                                       score[j] = temp;          
                                       names1[j] = tmp_string;
                            }    
                    }   
              } 
              //sort by score (div2)  
              for ( int i = 0; i < 4; i++ )  
              { score2[i];   
                    for ( int j = 0; j < 4; j++ )     
                    {       
                            if( score2[i] > score2[j] )       
                            {          
                                       string tmp_string;          
                                       int temp;           
                                       temp = score2[i];            
                                       tmp_string = names2[i];           
                                       score2[i] = score2[j];           
                                       names2[i] = names2[j];           
                                       score2[j] = temp;          
                                       names2[j] = tmp_string;
                            }    
                    }   
              }

              //Points
              for ( int i = 0; i < 4; i++ ) 
              {
              if ( names1[i].score[i] == 0 )
              names1[i].points = 0;
              else
              names1[i].points = i + 1;
              }
              for ( int i = 0; i < 4; i++ ) 
              {
              if ( names2[i].score2[i] == 0 )
              names2[i].points = 0;
              else
              names2[i].points = i + 1;
              }

              //output
               cout << "DIVISION 1" << endl;
              for ( int k = 0; k < 4; k++ ) 

              {
                      cout << endl; 

                      cout << names1[k] << ": "<< score[k] << "                 ";
                      }

              cout << endl << endl;   
              cout << "DIVISION 2" << endl;
              for ( int k = 0; k < 4; k++ ) 
              {
                      cout << endl; 
                      cout << names2[k] << ": "<< score2[k] << "                 ";



                      }
              system("pause");
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

>if ( names1.score == 0 )
score isn't a member of the std::string class, so you can't use the dot operator like this. You follow the same pattern quite a bit, but I'm not entirely sure I can anticipate what you were trying to do.

>>if ( names1.score == 0 )
she's probably using that from an example shown to her using a struct to sort and is still trying to use it.

so then how would I go about doing that?
I need to assign points, but if the score is 0, it gets 0 points.. Would you konw how to do this?

>she's probably using that from an example shown to her using a struct to sort and is still trying to use it.
What's your point? That doesn't make it any less broken, but it's certainly a good lesson on taking care when mixing code from unique solutions.

>if ( names1.score == 0 )
score isn't a member of the std::string class, so you can't use the dot operator like this. You follow the same pattern quite a bit, but I'm not entirely sure I can anticipate what you were trying to do.

I know.. its an int, not string.

SO what should I do instead of the dot operator?

What I was tryign to do, was assign points based off of the index.
If there were 5 scores, the highest score gets 5 (highest points given are 5, becuase there are 5 total scores). The next highest gets 4, etc etc. The lowest score will get 1 point.
However, if the score is "0", then they will recieve "0" points.

Is taht possible?

>so then how would I go about doing that?
Instead of pretending that everything is encapsulated into one nice array, you have to treat the arrays as parallel. Maybe something like this:

for ( int i = 0; i < 4; i++ ) 
{
  if ( score[i] == 0 )
    points[i] = 0;
  else
    points[i] = i + 1;
}

And so forth. As long as the index refers to the corresponding data between score and points, you're good.

>Would you konw how to do this?
No, of course I wouldn't. It's not like I haven't described it at least three times to you over the course of multiple threads or anything. :icon_rolleyes:

Yes that's possible, once you have sorted them you can assign their points. Since they are already sorted that makes it nice and easy. Would you like an example?

Ok.. Well I went ahead and put that in there... but all its doing is giving everybody "45" points. instead of 5 points, 4 points, 3 points, 2 points, 1 point. & If only ONE person has a "0", then it gives everybody "0"s.

>>>>Would you like an example?


An example would be wonderful, thank you.

You all are so good at this.

If you dont mind me asking,
but what books/online tutorials would you recommend?
Because you obviuosly know alot about programming, and
I'd like to know more, as well.

>You all are so good at this.
It shouldn't be surprising. I, for example, probably have a good decade more experience than you.

>I'd like to know more, as well.
The best way to learn is to write programs, experiment with new things, and make mistakes. You can only learn so much from books and tutorials.

I don't know if this is exactly what you want but it should give you a hint:-

#include <iostream> 
#include <string> 

using namespace std; 

int main()
{
      
      string names[4] = {"Anna" , "Jenny", "George" , "Michael"};   
      int score[4];
      
      
      
      for(int i = 0; i < 4; i++) 
      { 
            cout << names[i] << ": ";     
            cin >> score[i];     
            cin.ignore(); 
            }
            
              //sort by score   
              for ( int i = 0; i < 4; i++ ) 	
              {    
                    for ( int j = 0; j < 4; j++ )     
                    {       
                            if( score[i] > score[j] )       
                            {          
                                       string tmp_string;          
                                       int temp;           
                                       temp = score[i];            
                                       tmp_string = names[i];           
                                       score[i] = score[j];           
                                       names[i] = names[j];           
                                       score[j] = temp;          
                                       names[j] = tmp_string;
                            }    
                    }   
              } 
              
              int numberOfPeople = 4;

              for ( int k = 0; k < 4; k++ )   
              {
                       
                      cout <<names[k] << " = "<< score[k] << "  points:" << numberOfPeople <<endl;
                      numberOfPeople = numberOfPeople - 1;
       
             }
            system("pause");
}

look at the parts in red.

Alright.. I got it working. omg i'm so excited. lol

However,
if somebody gets "0" as their score, i need it to have "0" points.

How would I go about doing that?

Did you want me to show you that as well?

If its not too much hassle...
Its all very appreciated.

I'm almost done with it.
Just need to be able to set the "0" score to "0" points,
and then print.

:) thank you so much.

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