I am having trouble with making my program read in binary and convert it into an integer so that I can do arithmetic on it, and then output it back out as binary.
Here is my code. The first part of it works, and I can read in the 2 binary numbers, but when I have a problem with the segment that converts it into an integer.
#include <stdio.h>
#include <string.h>
int main()
{
int i, num1, num2, num3=0;
unsigned choice, string;
char str1[7], op, str2[8], str4[8];
int str3[8]={64,32,16,8,4,2,1};
do
{
system("clear");
printf("Enter an Operation?\n");
printf("Yes(1) or No(2)\n");
scanf("%u", &choice);
}while (choice < 1 || choice > 2);
{
switch(choice)
case 1:
{
printf("Enter two binary numbers seperated by an operator: ");
scanf("%7s%c%8s", str1, &op, str2);
for (i==0; i<=7; i++) //this is where the problem is.
scanf("%d", &str3[i]);
if(str1[i]=1);
num1==(num1+str3[i]);
if(str1[i]=0);
num1==(num1 + 0);
if (str2[i]=1);
num2==(num2+str3[i]);
if(str2[i]=0);
num2==(num2+0);
if (op=='+')
num3==(num1+num2);
if(op=='-')
num3==(num1-num2);
if(op=='*')
num3==(num1*num2);
if(op=='/')
num3==(num1/num2);
for (i=0; i<=7; i++)
str4[i]=(num3 % 2);
system("clear");
printf("%s%c%s", str1, op, str2);
printf("\nequals %d", num3);
break;
case 2:
printf("goodbye");
while(choice !=2);
return 0;
}
}
}