#include <iomanip>
#include <iostream>
#include <string>
usingnamespace std;
bool checkbinary(long);
int convertBtoD(long);
void drawline(char);
void header ();
void body(int, long);
int main()
{
int n; // taking inputs
long A[20];
cout << "Please enter the number of binary values desired: ";
cin >> n;
while ( (n < 0) || (n > 20) )
{
cout << "ERROR: THE NUMBER ENTERED IS IN-VALID; PLEASE RE-ENTER: ";
cin >> n;
cout << endl;
}
for ( int k = n; k > 0; k--)
{
cout << "Please enter the Binary number: ";
cin >> A[n];
if (!checkbinary(A[n]))
cout << "ERROR: NUMBER NOT A BINARY NUMBER; PLEASE RE-ENTER: ";
cin >> A[n];
}
drawline ('#');
header();
drawline ('-');
for (int c = n; c >= 1; c++)
body(n, A[n]);
drawline ('#');
system ("pause");
}
void drawline(char $)
{
for (int c = 1; c<=30; c++)
cout << $;
cout << endl;
}
void header()
{
cout << setw(15) << "Binary" << setw(15) << "Decimal" << endl;
}
void body(int n,long A[20])
{
for ( int c = n; c > 0; c--)
cout << setw(15) << A[n] << setw(15) << convertBtoD(A[n]) << endl;
return;
}
bool checkbinary(long bin)
{
int d;
while (bin !=0)
{
d = bin % 10;
bin = bin / 10;
if ( (d != 1) || (d !=0) )
returnfalse;
}
returntrue;
}
int convertBtoD (long num)
{
int d = 0, w = 1;
while (num != 0)
{
d = d + (num % 10) + w;
num/=10;
w = w * 2;
}
return w;
}
The output should look like this
####################################
binary decimal
------------------------------------
1101 ..
11111 ...
and so on
####################################
However, I keep receiving this
/tmp/ccsUb3eq.o: In function `main':
:(.text.startup+0x161): undefined reference to `body(int, long)'
collect2: error: ld returned 1 exit status