Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Displaying arrays values in another function

MechEngMechEng Member Posts: 1
HI , I really need help here
The program should goes like this : if the user choose '1' he will enter values for an array with size 6 or less , and then if he chooses '2' the values should be viewed in the screen , so i should have 2 functions , and sth wrong here and i don't know where so i need help :

[code]
#include
using namespace std;

char minu();
void readArray(int a[], int size);
void displayArray(const int a[],int size);

int main()
{
int a[6], size = 0;
char op;

cout << "Welcome to the Array Handler!

";
cout << "Important Note: Maximum array size is 6!!

";
op = minu();
while(op != 'q')
{
switch (op)
{
case '1': readArray(a, size);
break;

case '2': displayArray(a, size);
break;
}


op = minu();
}


return 0;

}

char minu()
{
char op;
cout << "1. Read array" << endl << "2. Display array"<< endl;
cout << "Enter operation number or 'q' to quit: " ;
cin >> op;
return op ;
}

void readArray(int a[], int size)
{
int i;
cout << "Enter array size: ";
cin >> size;
if (size <6)
for (i=0 ;i<size ; i++)
{
cout << endl << "a[" << i << "] = ";
cin >> a[i];
}
else
cout << "sorry ! too big for me" << endl;


}



void displayArray( const int a[], int size )
{
for ( int i = 0; i < size; i++ )
cout << a[i] << ' ';
}






[/code]
Sign In or Register to comment.