The problem ask to enter numb of students up to 100.
but the user enter let's say 10.

how do i manage to do that in arrays. Sorry if is a bother but i'm a newbie lol.

The problem ask to enter numb of students up to 100.
but the user enter let's say 10.

how do i manage to do that in arrays. Sorry if is a bother but i'm a newbie lol.

Two options. Declare an array statically with 100 elements (max elements) or ask the user for the number of students, then use that number to allocate the array dynamically. The set up a for-loop and ask the user for input one student at a time.

That's vague, so if you want more specific help, you'll need to be more specific in your question and show some code or something.

# include <iostream>
using namespace std;

void enterNumbStudents ( int numb[]);
void enterscores ( int scores[]);
int max_SIZE=100;
int index=0;
int main ()
{
 
 int numb;
 int scores;
 int S[max_SIZE];
 enterNumbStudents (index);
 enterscores (S);
 
 
 
    
    
system ("pause");
return 0;
} 

//-------------

void enterNumbStudents(int numb[])
{
     
cout<<"Enter the number of students up to 100";
cin>> numb[index];     
     
     
}

//-------------------------

void enterscores ( int scores[])
{
int i=0;
cout<<"Enter the 6 score";

for (i=0;i<index;score++)
{
cin << scores[score];     
}     

}

this is what i got so far but it isn't working probperly .

# include <iostream>
using namespace std;

void enterNumbStudents ( int numb[]);
void enterscores ( int scores[]);
int max_SIZE=100;
int index=0;
int main ()
{

 int numb;
 int scores;
 int S[max_SIZE];
 enterNumbStudents (index);
 enterscores (S);





system ("pause");
return 0;
} 

//-------------

void enterNumbStudents(int numb[])
{

cout<<"Enter the number of students up to 100";
cin>> numb[index];     


}

//-------------------------

void enterscores ( int scores[])
{
int i=0;
cout<<"Enter the 6 score";

for (i=0;i<index;score++)
{
cin << scores[score];     
}     

}

Do you have any indentation or did it just get stripped out with the lack of code tags?

Seems to me this function should not be this:

void enterNumbStudents ( int numb[]);

but rather this:

int enterNumbStudents ( );

Ask the user for a single integer and return it. There's no need for this function to involve an array as far as I can tell.

Edited 3 Years Ago by happygeek: fixed formatting

This question has already been answered. Start a new discussion instead.