I am doing C++ assignment, it invols designing a program where the user can put binary numbers and gets a word in result.
I have done the first part of the program but i am strugling to do the the last to tasks.
Here is what i have done so far
#include <iostream>
using namespace std;
void main(void)
{
int binaryword(int binary, int bits[]); // function prototypes
void display(int binary, int x[]);
int bit,binary=0,i;
int bits[20]; // declare an array, max size 20 elements
for (i=0;i<19;i++) bits[i]=0; // good practice to initialise array
cout << "enter only 0 and 1 \n\n";
cout << "End by entering any negative number \n\n";
do // example of a do ... while loop
{
cin >> bit;
if ((bit == 0) || (bit ==1))
{
bits[binary]=bit; // store current number in array
binary++; // increment number count
}
else
{
cout << "-ve number entered, bye bye\n";
}
} while((bit == 0) || (bit ==1));
// now call the display function to show the array
display(binary,bits); // don't need []after the 'numbers' parameter
} // of main
// Function to display the array
void display(int binary, int x[]) // parameter order matters not the name
{
for (int j=0;j<binary;j++) // notice int can be declared in the for statement
{
cout << x[j];
}
} // of display function
That is not it, i have to convert it to decimal so the user can type binary numbers and get a word
please HELP
Cheers