### convert to array

hey guys, can anyone help me how to make an array out of this?
 ``123456789101112131415161718192021222324252627`` `````` #include using namespace std; void decToBin(int num, int base); int main() { int decimal; cout<<"Enter the number you want to convert? : "; cin>>decimal; cout<<"\nIn binary is : "; decToBin(decimal, 2); } void decToBin(int num, int base) { if(num > 0) { decToBin(num/base , base); cout<
out of what?
@TheJJJunk this code shown here. how can i make it into array? :-)
You have the number, the base, the new result, which do you want to make into an array?
Last edited on
@TheJJunk that's what im asking for help. i dont know how to make an array out of that. please do help me.
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.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include using namespace 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<
Last edited on
Topic archived. No new replies allowed.