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.

Recommended Answers

All 5 Replies

well, it sounds like what you really should be using is a dynamic container like a vector, or a list...arrays are good, but they tend to waste precious memory :)

I can understand if you're a noob, but vectors aren't hard at all:
http://cplusplus.com/reference/stl/vector/

Hope I helped :)

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.

hey thanx for all the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.