# Binary to Decimal Converter

This is a discussion on Binary to Decimal Converter within the C Programming forums, part of the General Programming Boards category; I'm trying to make a program that takes up to a seven digit binary number and converts it to its ...

1. ## Binary to Decimal Converter

I'm trying to make a program that takes up to a seven digit binary number and converts it to its decimal equivalent. I'm still a beginner, so this might be a simple question but how do I stop the user from entering anything but 1s and 0s? This means no decimals or numbers other than 1 or 0.

I already made it so it won't accept anything below 0 or above 1111111.

2. Welcome to the forum. Next time you post, make sure you post your try in code tags, like these [code]/* your code*/[/code].

Because it's your first post, I am going to give a sample code, in order to get ideas. Let's say I have an array, that I wanted to be filled only with zeroes and ones, by the user, in whatever cell the user wants too.
I could do that with this code
Code:
```#include <stdio.h>

int main(void)
{
int array[5];

/* i will go through all the cells of the array */
int i;

for( i = 0 ; i < 5 ; i++)
{
do{
/* Print message and read element,
* until it gets the value 1 or 0 */
printf("Input %i-th element\n", i);
scanf("%d", &array[i]);
}while(array[i] != 1 && array[i] != 0);
}

printf("The array is:\n");
for( i = 0 ; i < 5 ; i++)
{
printf("array[%d] = %d\n", i, array[i]);
}

return 0;
}```