Need help "From any base to base 10"

Can you correct my. It is not following the statement that I put and can you put this in character array. NOTE THIS "TURBO C++".

#include<iostream.h>
#include<conio.h>
#include<stdio.h>


char value;
char t, u, v;
char answer;

void Binary2Decimal()
{
gotoxy(1,17);printf("[BINARY TO DECIMAL CONVERSION]");


char b2,f2=1,d2=0;
gotoxy(1,19);printf("Enter a Binary number: ");
scanf("%d", &b2);

printf("\n\n");

while(b2>0)
{
if((b2%10)==1)
{
d2=d2+f2;
}
b2=b2/10;
f2=f2*2;
}
printf("Decimal equivalent is: ", &d2);

}

void Octal2Decimal()
{
gotoxy(1,17);printf("[OCTAL TO DECIMAL CONVERSION]");


char number4,dec7,rem7,i7,sum7;
gotoxy(1,19);printf("Enter an Octal number: ");
scanf("%o", &number4);

printf("\n\n");

dec7=printf("%d", number4);

{
rem7=dec7%8;
sum7=sum7 + (i7*rem7);
}

printf("Decimal equivalent is: %d", number4);

}

void Hexa2Decimal()
{
gotoxy(1,17);printf("[OCTAL TO DECIMAL CONVERSION]");


char number4,dec7,rem7,i7,sum7;
gotoxy(1,19);printf("Enter an Octal number: ");
scanf("%o", &number4);

printf("\n\n");

dec7=printf("%d", number4);

{
rem7=dec7%8;
sum7=sum7 + (i7*rem7);
}

printf("Decimal equivalent is: %d", number4);

}
int main()

{

do{
clrscr();

printf("Conversion from any base to base 10");


gotoxy(1,3);printf("a - Binary");
gotoxy(1,4);printf("b - Octal");
gotoxy(1,5);printf("c - Hexadecimal");


gotoxy(1,7);printf("Select a value to be converted: ");
scanf("%c", &value);

switch(value){
case 'a':
Binary2Decimal();
break;
case 'b':
Octal2Decimal();
break;
case 'c':
Hexa2Decimal();
break;
default:
printf("Wrong input");
}

gotoxy(1,22);printf("Do you want to continue NUMBER CONVERSION?(y/n) ");
scanf("%c", &answer);
}

while(answer == 'y');
getch();
}
in your Octal2Decimal() routine

scanf("%o", &number4);

that actually scans an octal into an int. all of the conversion is already done for you. so you can go straight to...
printf("Decimal equivalent is: %d", number4);

your Hexa2Decimal() routine is just a copy of the octal one.

Binary2Decimal() looks like it should work.

My Binary2Decimal() when I input a binary number it doesn't give an answer it will skip the "Decimal Equivalent is: " and it go straight to the "Do you want to continue?(y/n)"

and in my void main it will not go to looping?
sorry for the late reply, but here it is for completeness.

printf("Decimal equivalent is: ", &d2);

there are no %d in your format string.
And surely you want to print the value of d2, no tits address?

i left that typo in on purpose, happy tuesday :)

Last edited on
Topic archived. No new replies allowed.