Passing Arrays Through Functions

I am writing a code for a simple calculator that will perform several decimal conversions (I am currently concerned with 1 as of right now). Essentially after the user makes the selection in the menu (switch statement) I want to have a separate function to perform the actual conversion (math) and a function that is reserved for the solution (output). I need help with passing the binaryarray created in mathoption1 to outputoption1. The code now does not compile, I have 4 errors associated with the parameters of some of the functions. Obviously, I am lost and could use some guidance. Any help/input/advice would be greatly appreciated.

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
 #include <iostream>

using namespace std;

void display();
void menu(int &option);
void outputoption1(int decimal, int binaryarray[]);
void mathoption1(int &decimal);


int main()
{
	int option;
	int binaryarray[32];

	display();
	menu(option);

	return 0;
}

void display()
{
	cout << "Industrial Engineering Decimal Conversion v 1.0\n" << endl;
	cout << "Created by: asdf adsfadf\n"
	     << "\t    adsfa adsfad\n" << endl;
	cout << "On the next screen, you will choose which operation you want to perform\n" << endl;

	system("PAUSE");
	cout << "\n" << endl;
}

void menu(int &option, int decimal, int binaryarray[])
{
   cout << "Welcome to the IE Decimal Conversion Program!\n\n"
		<< "To choose a conversion, enter a number from the menu below\n\n"
		<< "1) Decimal to Binary\n"
		<< "2) Quit the program\n" << endl;

   cin >> option;

   switch (option)
   {
   case 1:
	   mathoption1(decimal);
	   outputoption1(decimal, binaryarray[]);
	   break;
   case 2:
	   break;
   default:
	   cout << "ERROR: Please make a valid selection" << endl;
	   menu(option);
   }
}

void mathoption1(int decimal)
{
	cout << "Please input the decimal you want to convert to binary/n/n";
	cin >> decimal;

	int x = 0;
	int binaryarray[32];
	while (decimal != 0)
	{
		binaryarray[x] = decimal % 2;
		x++;
		decimal = decimal / 2;
	}

}

void outputoption1(int decimal, int binaryarray[])
{
	int x = 0;
	cout << "Your original decimal value of " << decimal << " is equivalent to the following binary value:\n";
	for (int y = x - 1; y >= 0; y--)
	{
		cout << binaryarray[y];
	}
}
Your main problem seems to be that you declare functions with certain parameters, but when you implement them you have a different set of parameters. See line 6 and line 33 for menu function, and lines 8 and 56 for mathoption1.

Also, when you call outputoption1 on line 46, binaryarray is already an array, so you should not put the square brackets on that line
Topic archived. No new replies allowed.