int array1[50];
int array2[30]
int array3[23]
int array4[47]
int array5[35]
int array6[95]
int array7[120];
And there are many other combinations! :-)
Nah, but seriously: Yes. Without knowing what you want or need exactly, you would have to keep track of the total number of elements in each array, and then check the total (the sum of all these element counts) BEFORE allowing a new entry in any of the arrays. Use a centralized function for this.
As WebJose says, as each array has something added to it, increase a number that started at zero. When that number reaches 400, refuse to allow anything else to be added to the arrays.
im not being too clear. every array can only hold 255 individually. i want to figure out if i can make it to where all 7 arrays added together can only hold 400 max. would this work?
int array1[255];
int array2[255];
int array3[255];
int array4[255];
int array5[255];
int array6[255];
int array7[255];
Your problem is that you want to not let any more value stored inside any of these array if 400 values are stored OR
to just allocate 400 places and store 400 values.
By the second option I mean you realize that by using arrays you have allocated 7*255 int already right? If you don't then you need to go around this by allocating dynamically array by demand.
If it's the first case you are interested in then the suggested solution are both satisfactory and easy to implement. Just define a function that do all the value assignments and contain a counter of the values assigned so far. If this is reached prohibit any more storing of values.
lets say we are playing a video game and you can get points to go towards stats
int strength[255];
int defense[255];
int vitality[255];
int endurance[255];
int speed[255];
now every stat can be enhanced to reach 255, but i want it to where collectively you can only have it to where you can only have 500 points for all of the stats combined. any idea on where to start with this?
struct STATS //Stats are saved in a single structure.
{
int strength; int defense; int vitality; int endurance; int speed;
};
enum ATTRIBUTE { str, def, vit, end, spd, };
STATS level_up(STATS stats, int attribute)
{
int total_stats = stats.strength + stats.defense + stats.vitality + stats.endurance + stats.speed;
if (total_stats >= 500) return stats; // Don't level up if total stats are 500.
switch (attribute)
{
case str:
if (strength < 255) stats.strength++; // Increase strength if str was selected and is not above 255
break;
case def:
...
}
return stats;
}