Hi I need help to correct this program :( NOTE THIS IS "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();
}

Help anyone. My head is hurting correcting this program own my own :( That program won't follow some of the statements that I put. And I don't know to put this in character array :(

Ok ... you still need to clean it up a lot ...
I only edited enough so that I could compile it with an up to date C++ compiler ... and run it so it would not crash ...

Fixed up formatting a bit ... too ... so that you could BETTER see the progression of program flow ...

You need to use descriptive variable names.

In C++, the prefered way to declare your variables, is to declare them just before you use them ... and with just enough scope ONLY as you need!

//#include<iostream> // not used ... using ctdio
#include <cstdio>

//#include<conio.h>
//#include <windows.h>

using namespace std;

/*
void gotoxy( SHORT x, SHORT y )
{
    COORD coord = { x, y };
    SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
*/
void flushStdin()
{
    while( getchar() != '\n' ) ; // "flush" stdin ...
}

int Binary2Decimal()
{
    //gotoxy(1,17);
    printf("[BINARY TO DECIMAL CONVERSION]\n");

    //gotoxy(1,19);
    printf("Enter a Binary number: ");
    int b;
    scanf("%d", &b);
    flushStdin();

    printf("\n\n");

    int d=0, f=1;
    while(b>0)
    {
        if((b%10)==1)
        {
            d=d+f;
        }
        b=b/10;
        f=f*2;
    }
    printf("\nDecimal equivalent is: %d\n", d);

    return 0;

}

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

    unsigned dec7,rem7,i7,sum7;
    //gotoxy(1,19);
    printf("Enter an Octal number: ");
    unsigned oct;
    scanf("%o", &oct);
    flushStdin();

    printf("\n\n");

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

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

    printf("\nDecimal equivalent is: %d\n", oct);
}

void Hexa2Decimal()
{
   // gotoxy(1,17);
    printf("[HEX TO DECIMAL CONVERSION]\n");


    unsigned number4,dec7,rem7,i7,sum7;
    //gotoxy(1,19);
    printf("Enter a Hex number: ");
    scanf("%x", &number4);
    flushStdin();

    printf("\n\n");

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


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

    printf("\nDecimal equivalent is: %d\n", number4);
}




int main()
{
    char answer = 'y';
    do
    {
        //clrscr();

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

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

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

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

        //gotoxy(1,22);
        printf("Do you want to continue "
                                "NUMBER CONVERSION? (y/n) ? ");
        scanf("%c", &answer);
        flushStdin();
        putchar( '\n' );
    }
    while(answer != 'n');
}
commented: helpfull +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.