samedi 6 novembre 2021

Pointer Array problems

Hello everyone I am having some trouble with my array, in particular, the functions for the array. It is not showing up with errors until I build it. ''' //This is my menu choice

switch (Menu_Choice) //switch function to direct users to their menu choice.
    {
        case 1://menu option to display ratings.
            cout << "Display Ratings\n";
            displayRatings(*ratings);
            break;

        case 2://menu option to change a rating.
            cout << "Change A Rating\n";
            ChangeARating(ratings,NUM_PEOPLE);
            break;}

This is my function to change a rating

void ChangeARating(int *ratings, int NUM_PEOPLE)
 {
    person = getvalidperson(0);

    rating = getvalidrating(NUM_PEOPLE);

    ratings[person-1]=rating;
 }

This is my display rating code

void displayRatings(const int * ratings, int NUM_PEOPLE)
 {
    for ( i=0 ; i<=835 ; i++)
    {
        cout << ratings[i] <<" ";
        if(i%15==0 && i!=0 || i ==835)
        {
            cout <<"\n"; //this allows for the array to have an end line after every 15 
     characters.
        }
    }
}

These are my global variables

int rating;
void displayRatings(int ratings);
void ChangeARating(int *rating,int NUM_PEOPLE);
int i;
void getValidPerson(int &num);
int person;

And finally here's my pointer array

int NUM_PEOPLE = 835;
int *ratings = new int[NUM_PEOPLE]
        {// this is the array, all the info.
                3, 1, 5, 5, 1, 6, 4, 5, 1, 3, 4, 4, 4, 4, 1, 6, 6, 6, 3, 6, 6, 1, 4, 6, 6, 4, 4, 6, 6, 6, 6, 3, 2, 6, 4, 5,
                6, 5, 6, 5, 6, 5, 6, 4, 6, 4, 5, 6, 4, 6, 6, 5, 5, 1, 4, 6, 1, 6, 6, 6, 5, 4, 6, 6, 5, 4, 4, 3, 3, 6, 5, 6,
                6, 6, 6, 6, 1, 5, 6, 1, 6, 1, 6, 3, 1, 2, 6, 5, 4, 6, 2, 3, 3, 1, 1, 4, 3, 3, 3, 4, 6, 4, 4, 2, 6, 3, 4, 3,
                5, 1, 2, 4, 4, 6, 1, 4, 4, 4, 4, 4, 4, 4, 3, 4, 6, 4, 2, 1, 4, 3, 3, 6, 1, 2, 5, 6, 5, 4, 5, 5, 5, 6, 4, 3,
                6, 4, 6, 6, 6, 4, 1, 6, 5, 3, 2, 4, 5, 4, 6, 2, 3, 1, 5, 4, 5, 2, 5, 3, 1, 5, 3, 4, 4, 1, 4, 4, 1, 4, 5, 5,
                4, 4, 3, 4, 3, 1, 4, 3, 4, 4, 1, 4, 6, 2, 3, 4, 4, 4, 6, 6, 5, 5, 6, 3, 6, 4, 5, 6, 2, 4, 1, 3, 1, 4, 5, 4,
                4, 2, 1, 6, 3, 3, 3, 6, 1, 4, 1, 4, 1, 4, 2, 6, 4, 3, 5, 1, 3, 2, 1, 6, 4, 2, 4, 5, 5, 4, 4, 4, 5, 4, 2, 3,
                4, 4, 4, 2, 3, 4, 4, 1, 2, 6, 6, 4, 4, 3, 4, 3, 3, 6, 3, 1, 1, 4, 2, 2, 4, 1, 4, 4, 6, 1, 1, 6, 1, 4, 4, 3,
                5, 4, 1, 4, 4, 6, 6, 4, 6, 4, 4, 4, 6, 6, 6, 6, 4, 1, 4, 4, 4, 6, 2, 3, 4, 6, 4, 3, 4, 1, 6, 6, 3, 3, 5, 6,
                5, 4, 6, 5, 4, 6, 4, 5, 4, 4, 4, 4, 1, 4, 6, 1, 3, 6, 6, 4, 1, 3, 6, 1, 6, 4, 6, 5, 2, 3, 1, 3, 4, 5, 1, 1,
                2, 5, 4, 5, 3, 3, 3, 3, 4, 4, 5, 2, 1, 4, 4, 2, 3, 3, 4, 6, 6, 4, 4, 1, 3, 1, 2, 4, 6, 4, 6, 1, 4, 2, 2, 1,
                4, 6, 4, 6, 4, 4, 1, 4, 5, 2, 1, 3, 3, 5, 2, 5, 4, 4, 6, 6, 6, 2, 3, 2, 4, 2, 1, 4, 1, 6, 3, 2, 5, 3, 4, 4,
                1, 3, 1, 2, 5, 6, 6, 2, 4, 4, 4, 3, 3, 6, 1, 6, 4, 4, 2, 2, 4, 5, 6, 2, 6, 3, 3, 3, 3, 2, 4, 4, 2, 4, 3, 3,
                1, 2, 4, 6, 4, 6, 2, 3, 2, 2, 3, 1, 4, 5, 3, 4, 4, 5, 4, 3, 4, 5, 4, 1, 4, 3, 6, 5, 1, 2, 4, 1, 5, 4, 1, 1,
                6, 6, 2, 5, 5, 5, 6, 6, 6, 3, 6, 4, 6, 4, 3, 3, 3, 3, 4, 4, 6, 4, 5, 1, 5, 6, 6, 3, 6, 3, 1, 6, 3, 1, 4, 1,
                5, 5, 4, 1, 4, 5, 6, 3, 3, 2, 6, 3, 5, 4, 4, 2, 4, 1, 1, 4, 4, 6, 4, 1, 6, 3, 4, 5, 4, 5, 4, 1, 1, 6, 3, 3,
                1, 6, 3, 2, 1, 4, 3, 4, 1, 1, 4, 4, 1, 1, 4, 3, 4, 1, 6, 3, 4, 6, 1, 5, 6, 4, 6, 6, 1, 4, 6, 6, 4, 4, 1, 1,
                4, 6, 1, 5, 4, 4, 4, 4, 1, 2, 3, 5, 3, 3, 3, 1, 1, 4, 4, 1, 5, 1, 6, 3, 4, 2, 4, 6, 6, 5, 4, 6, 2, 5, 5, 1,
                4, 3, 6, 1, 6, 5, 6, 6, 1, 5, 1, 4, 2, 1, 4, 3, 6, 4, 1, 5, 2, 6, 6, 1, 1, 4, 1, 4, 3, 1, 1, 3, 4, 3, 1, 1,
                4, 5, 6, 3, 2, 4, 4, 3, 4, 4, 3, 5, 4, 1, 6, 6, 2, 1, 1, 4, 1, 3, 5, 6, 3, 2, 3, 4, 1, 6, 5, 2, 5, 6, 2, 4,
                1, 3, 6, 2, 4, 2, 5, 2, 1, 3, 3, 2, 5, 4, 3, 4, 5, 6, 2, 6, 3, 4, 5, 5, 4, 6, 4, 6, 6, 4, 5, 4, 4, 6, 2, 5,
                4, 6, 4, 1, 4, 6, 4, 3, 3, 3, 4, 4, 2, 4, 6, 4, 5, 6, 1, 3, 4, 4, 3, 6, 1, 3, 5, 4, 6, 1, 4, 3, 1, 1, 1, 3,
                3, 4, 5, 1, 4, 1, 6, 4, 1, 4, 1, 3, 4, 6, 5, 3, 6, 6, 4, 3, 2, 3, 3, 4, 5, 5, 5, 6, 3, 4, 6, 2, 5, 1, 1, 2,
                1, 3, 3, 5, 4, 4, 6
        };

My main problems are displaying and changing the rating. The error i recieve when building this program is: Undefined symbols for architecture x86_64: "displayRatings(int)", referenced from: _main in array.cpp

Aucun commentaire:

Enregistrer un commentaire