Quantcast
Viewing all articles
Browse latest Browse all 2703

Displaying arrays values in another function

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 :

#include <iostream>
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!\n\n";
	cout << "Important Note: Maximum array size is 6!!\n\n";
	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] << ' ';
} 


Viewing all articles
Browse latest Browse all 2703

Trending Articles