programming with arrays and variables

Hey!
i’ve been trying to get my project to work but my code won;t compile anymore because i have substituted part of a variable’s name by an array element (which should come to the same). The whole code is very long but essentially, I’ve got all these variables declared:

int selected_user = 0;
int selected_angle = 14;
int page_count = 0;
int selected_temperature = 20;
int selected_curtains = 20;

int common_morning_personalised = 0;
int common_afternoon_personalised = 0;
int common_evening_personalised = 0;
int common_night_personalised = 0;
int common_party_personalised = 0;

int dan_morning_personalised = 0;
int dan_afternoon_personalised = 0;
int dan_evening_personalised = 0;
int dan_night_personalised = 0;
int dan_party_personalised = 0;

int common_morning_roof = 0;
int common_morning_temperature = 0;
int common_morning_curtains = 0;

char* users[8] = {“common”, “dan”, “lory”, “A”, “B”, “C”, “D”, “E”};
char* presets[5] = {“morning”, “afternoon”, “evening”, “night”, “party”};

another bit of code saying:
if user = common ==> selected_user = 0
if user = dan ==> selected_user = 1

  • …*

for (int j=0; j<5; j++)
{
if ((page_count == (30+j)) && (users[selected_user]_presets[j]_personalised == 1))
{
selected_angle = users[selected_user]_presets[j]_roof;
selected_temperature = users[selected_user]_presets[j]_temperature;
selected_curtains = users[selected_user]_presets[j]_curtains;
}
}

It then returns me this error "error: expected ‘;’ before ‘_presets’
expected ‘)’ before ‘_presets’ "
which doesn’t make sense to me!

Is my substitution supposed to work? can I do that?
I have been stuck on this for days now so if anyone can help me with this it would be much appreciated!
Thanks
Arthur

You can't build variable names. Once the code is compiled, any concept of "names" for variables is gone and all the names are replaced with addresses. It looks like what you want to do is build a user class. Have a google at "C++ classes" and see if you don't find some inspiration.

ap14519:
Hey!
i’ve been trying to get my project to work but my code won;t compile anymore because i have substituted part of a variable’s name by an array element (which should come to the same). The whole code is very long but essentially, I’ve got all these variables declared:

int selected_user = 0;
int selected_angle = 14;
int page_count = 0;
int selected_temperature = 20;
int selected_curtains = 20;

int common_morning_personalised = 0;
int common_afternoon_personalised = 0;
int common_evening_personalised = 0;
int common_night_personalised = 0;
int common_party_personalised = 0;

int dan_morning_personalised = 0;
int dan_afternoon_personalised = 0;
int dan_evening_personalised = 0;
int dan_night_personalised = 0;
int dan_party_personalised = 0;

int common_morning_roof = 0;
int common_morning_temperature = 0;
int common_morning_curtains = 0;

char* users[8] = {“common”, “dan”, “lory”, “A”, “B”, “C”, “D”, “E”};
char* presets[5] = {“morning”, “afternoon”, “evening”, “night”, “party”};

another bit of code saying:
if user = common ==> selected_user = 0
if user = dan ==> selected_user = 1

  • …*

for (int j=0; j<5; j++)
{
if ((page_count == (30+j)) && (users[selected_user]_presets[j]_personalised == 1))
{
selected_angle = users[selected_user]_presets[j]_roof;
selected_temperature = users[selected_user]_presets[j]_temperature;
selected_curtains = users[selected_user]_presets[j]_curtains;
}
}

It then returns me this error "error: expected ‘;’ before ‘_presets’
expected ‘)’ before ‘_presets’ "
which doesn’t make sense to me!

Is my substitution supposed to work? can I do that?
I have been stuck on this for days now so if anyone can help me with this it would be much appreciated!
Thanks
Arthur

May I suggest a 3 dimensional array?
Something like this …

 // 8 Users
 // 5 Presets
 // 4 Personalizations
 int Settings[8][5][4];

 // Set Common + Morning + Personalized to 1
 Settings[0][0][0] = 1;

 // Set Dan + Morning + Personalized to 2
 Settings[1][0][0] = 2;

 // Set Lory + Afternoon + Personalized to 3
 Settings[2][1][0] = 3;

 // Set A + Evening + Roof to 4
 Settings[3][2][1] = 4;
 
 // Set the "selected item" to 5
 Settings[selected_user][selected_preset][selected_personalization] = 5;

The first index is to access the USERS
The second index is to access the PRESETS
The third index is to access the PERSONALIZATIONS

And probably best to use DEFINES instead of the hard code values like: 8, 5 and 4.