Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ Question

  • 20-03-2003 1:36am
    #1
    Moderators, Arts Moderators, Recreation & Hobbies Moderators, Sports Moderators Posts: 9,588 Mod ✭✭✭✭


    This is a musical program problem

    I have a struct like the following:

    struct a_triplet
    {
    int first;
    int second;
    int third;
    }triplet;

    and I have about 297 individual notes, each with an associated pitch....stored in an array...something like

    pitch_array[note_counter];

    My problem is that I want to fill the triplet struct described above, with notes 1, 2, and 3 ....then fill a second triplet struct with notes 4, 5, 6... and a third with 7, 8, 9...and so on..

    I was thinking about doing this with an array of structs...but how exactly do I go about pumping in three notes, then skipping 3 and pushing another three into the next struct?


Comments

  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    how bout something like :

    int TOTALNOTES = 297; //or what ever your totalnotes will be

    triplet triplet_array[TOTALNOTES / 3] ; // since 3 notes per triplet

    then the for loop :

    for (int i = 0; i < TOTALNOTES; i+=3)
    {
    // the first element, i.e. num 1,4,7 etc
    triplet_array[i/3].first = pitch_array;
    // the second i.e. num 2,5,8 etc
    triplet_array[i/3].second = pitch_array[i+1];
    // the third i.e. num 3,6,9 etc
    triplet_array[i/3].first = pitch_array[i+2];
    }

    its a bit rough but you should get the jist of it


Advertisement