Hi, I'm new to programming and I need to write a program that will convert decimals to binary and the other way around, I've decided to start with converting decimals to binary. Here is my code, I keep getting the error invalid conversion from int to int*, anyone know why?
#include<iostream>
usingnamespace std;
int decimalToBinary(int a,int b[]);
int main()
{
int decimal;
int binary_number[10];
cout<<"Please enter a positive integer: ";
cin>>decimal;
decimalToBinary(decimal,binary_number);
}
int decimalToBinary(int a, int b[])
{
int count=0;
int result;
for (int i=0; i<=10; i++)
{
a=a%2;
b[i]=a;
count++;
}
cout<<"The integer "<<a<<" in binary form is: ";
for (int j=count-1; j>=0; j--)
{
cout<<b[j];
}
}
a=a%2; Let's say your 'a' was 100. 100%2 = 0 since 100 is even, so now your 'a' is 0 and it will remain so. Though if you had 103 you should get 1111111111..