Why do you need an array? You need to state what you want to turn into an array. Do you want an array to enter different values to convert? Do you want an array to store the binary results?
@TheJJunk our instructor asked us to make an array out of the problem that we solved. but i was having a hard time making an array out of it. i was so unfamiliar with array.
You could do this, which is assigning each number to an integer array index and then calling the function on each index. Or you could store all the values first, and then use another loop to call the function which displays them.
#include <iostream>
usingnamespace std;
void decToBin(int num, int base);
int main()
{
int decimal;
int number;
cout << "How many conversions do you want to do?: ";
cin >> number;
int array[number];
for (int i=0; i < number; ++i)
{
cout<<"Enter the number you want to convert? : ";
cin >> array[i];
cout<<"\nIn binary is : ";
decToBin(array[i], 2);
cout << endl;
}
}
void decToBin(int num, int base)
{
if(num > 0)
{
decToBin(num/base , base);
cout<<num%base;
}
}