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