Procedures and Array, quick tip please.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <iomanip>
using namespace std;


//Prototype
void menu();
void inputArray();
void sortNumbers();
void outNumb();
int Quit();



int main()
{
	
	int inputArray[10];
	int selection;
	int y;
	int x;
	int numArray[10];
	menu();

	cout << "Please make a selection" << endl;
	cin >> selection;


	switch (selection)
	{
		case 1:
			{
		if (selection = 1)
		{
				inputArray[y];
				menu();

				break;
			}

		case 2:
			{
			break;
			}
	
		case 3:
			{ 
				for (x = 0; x < y; x++)
				{
				cout << inputArray[x] << ", ";
				}
				break;
			}
		case 4:
			{
				break;
			}
			default: cout << "You suck at life, enter a real numnber" << endl;
	}


system ("pause");
return 0;

}
void menu()
{
	cout << "   (Menu)" << endl;
	cout << "1) Input Number" << endl;
	cout << "2) Sort Numbers" << endl;
	cout << "3) Output Numbers" << endl;
	cout << "4) Quit" << endl;

}

void inputArray(int numArray[], int length)
{
	
	int y;
	cout << "Please input one number: " << endl;
	cin >> numArray[y];

	for(int y = 0; y < 10; y++)
	{
		numArray[y];
	}
	}



I just need help with the array itself being stored one at a time in the array. It has to be a procedure. I can get the rest if I could get some help with this. How do i call the array back so after the user enters a number it stores it and brings the menu back up so they can make a selection again. The assignment question is as follows. Thanks in adavance.


The program should allow a user to input numbers into an array of integers. The array size should be 10. The first number should be stored in the zero position of the array. The next number should be stored in the next available location. Each option below should be written using a procedure, except Quit. Comment the procedures so that someone reading your source code will be able to know what type of data the procedure accepts, the functionality of the procedure and what data the procedure returns.
Try modifying your inputArray() function to something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
void inputArray(int numArray[], int length)
{
	
	int y=0;
        for( y=0;y<10;i++)
	{  if(y>9)break;
            if(i==0)cout << "Please input a number: " << endl;
            else if(i>0) cout<<"Enter next number: "<<endl;
	    cin >> numArray[y];
           
	
	}
}
Last edited on
Ok, but I am still getting some wierd errors from the compiler (visual basic). Has something to do with when i call back the procedure. If I use inputArray();
it gives a crazy error, but if i use inputArray(parameter, parameter); it says that inputArray does not take and parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <iomanip>
using namespace std;


//Prototype
void menu();
void inputArray(int numArray[], int length);
void sortNumbers();
void outNumb();
int Quit();



int main()
{
	int numArray[10];
	int length = 0;
	char selection;
	menu();


	if (selection = 1)
	{
		inputArray(numArray, length);
		
	}
	if (selection = 2)
	{
	
	}
	if (selection = 3)
	{
		for(int i = 0; i < length; i++)
			{
				for(int j = 0; j < length; j++)
				{
					cout << numArray[i] << ' ';
				}
					cout << endl;
			}
	}
			for (;selection = 4;)
			{
				break;
			}
	
	
	

		
	
system ("pause");
return 0;

}
void menu()
{
	char selection;
	cout << "   (Menu)" << endl;
	cout << "1) Input Number" << endl;
	cout << "2) Sort Numbers" << endl;
	cout << "3) Output Numbers" << endl;
	cout << "4) Quit" << endl;

	cout << "Please make a selection: ";
	cin >> selection;

}

	void inputArray(int numArray[], int length)

	{
		int a = 0;
		
		cout << "Please enter a number: " << endl;
		cin >> numArray[a];

		for(int a = 0; a < length; a++)
		{
		numArray[a];
		}

		
           
	
	}


This is what I have now, Option 1 should be pressed and then taken to the procedure inputArray(). Then after a number is entered, the menu should pop back up and if you want another number to be entered you select 1 again and so on and so forth up to ten numbers. if you want to print them you select option 3. I may have other errors, but i cant tell because the menu will not pop back up correctly no matter what i try. I just dont know where i need a loop to make sure that this occurs after a number is entered and stored in the array everytime. :S, I am going insane because it always feels like I have tried everything...when apperently I havent...Please help with anything you can. about the only thing I know for sure how to do on this is the selection sort.
Topic archived. No new replies allowed.