Ok the admin said to me not to post in C++ if my problem is in C language. Ok here's my problem with my program now. #1 If I put this in a array what should I change? #2 In my looping I needed to press double enter to enter in a loop but I only needed to press once the enter. #3 If I exit the program and I run it again the program will not clear screen it will show the text that the program shown in the last run. #4 Is my fucntion calling correct? NOTE THIS IS "TURBO C++ COMPILER"
#include<conio.h>
#include<stdio.h>
#include<math.h>
char base;
char key;
void Screen_Header();
void Binary2Decimal();
void Octal2Decimal();
void Hexa2Decimal();
int main()
{
Screen_Header();
Binary2Decimal();
Octal2Decimal();
Hexa2Decimal();
return 0;
}
void Screen_Header()
{
do{
clrscr();
gotoxy(1,3);printf("Conversion from any base to base 10");
gotoxy(1,5);printf("a - Binary");
gotoxy(1,6);printf("b - Octal");
gotoxy(1,7);printf("c - Hexadecimal");
gotoxy(1,11);printf("Select a base to be converted: ");
scanf("%c", &base);
switch(base){
case 'a':
Binary2Decimal();
break;
case 'b':
Octal2Decimal();
break;
case 'c':
Hexa2Decimal();
break;
}
gotoxy(1,20);printf("Press <DOUBLE ENTER> to Continue or Press <ANY KEY> to Exit ");
key=getch();
}
while(key == 13);
}
void Binary2Decimal()
{
gotoxy(1,13);printf("[BINARY TO DECIMAL CONVERSION]");
int bin2,f2=1,d2=0;
gotoxy(1,15);printf("Enter a Binary number: ");
scanf("%d", &bin2);
printf("\n");
while(bin2>0)
{
if((bin2%10)==1)
{
d2=d2+f2;
}
bin2=bin2/10;
f2=f2*2;
}
printf("Decimal equivalent is: %d", d2);
}
void Octal2Decimal()
{
gotoxy(1,13);printf("[OCTAL TO DECIMAL CONVERSION]");
long oct8,dec8,rem8,i8,sum8;
gotoxy(1,15);printf("Enter an Octal number: ");
scanf("%o", &oct8);
printf("\n");
{
rem8=dec8%8;
sum8=sum8 + (i8*rem8);
}
printf("Decimal equivalent is: %d", oct8);
}
void Hexa2Decimal()
{
gotoxy(1,13);printf("[HEXADECIMAL TO DECIMAL CONVERSION]");
long hex16,dec16,rem16,i16,sum16;
gotoxy(1,15);printf("Enter a Hexadecimal number: ");
scanf("%X", &hex16);
printf("\n");
{
rem16=dec16%16;
sum16=sum16 + (i16*rem16);
}
printf("Decimal equivalent is: %d", hex16);
}