What is wrong with this program?

Prongs298

In the zone
it exits after i enter the choice of the menu item..



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define MAX 1000
char v2;
void dectobin();
void octtobin();
void hextooct();
void hextobin();
void main(){
do
{

printf("WHAT DO YOU WANT TO DO?");
printf("\n1. DECIMAL TO BINARY.");
printf("\n2. OCTAL TO BINARY.");
printf("\n3. HEXADECIMAL TO OCTAL.");
printf("\n4. HEXADECIMAL TO BINARY.\n");

scanf("%c",v2);

switch(v2)
{
case '1':
dectobin();
break;
case '2':
octtobin();
break;
case '3':
hextooct();
break;
case '4':
hextobin();
break;
default:
printf("INVALID!!");
}
printf("\n\nDo you want to continue:\t");
scanf("\n\n%c",&v2);
}while(v2=='y');
getch();


}



//THIS PORTION IS FOR DECIMAL TO BINARY
void dectobin()
{


long int decimalNumber,remainder,quotient;
int binaryNumber[100],i=1,j;

printf("\n\nEnter any decimal number: ");
scanf("%ld",&decimalNumber);

quotient = decimalNumber;

while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}

printf("\nEquivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%d",binaryNumber[j]);
printf("\n\n-----------------------------");
printf("\n-----------------------------");
}
//THIS PORTION IS FOR OCTAL TO BINARY



void octtobin()
{


char octalNumber[MAX];
int k=0;

printf("\n\nEnter any octal number: ");
scanf("%s",octalNumber);

printf("\nEquivalent binary value: ");
while(octalNumber[k]){
switch(octalNumber[k]){
case '0': printf("000"); break;
case '1': printf("001"); break;
case '2': printf("010"); break;
case '3': printf("011"); break;
case '4': printf("100"); break;
case '5': printf("101"); break;
case '6': printf("110"); break;
case '7': printf("111"); break;
default: printf("\nInvalid octal digit %c ",octalNumber[k]);
}
k++;
}
printf("\n\n-----------------------------");
printf("\n-----------------------------");
}
//THIS IS FOR HEXA TO BIN

void hextobin()
{



char binaryNumber2[MAX],hexaDecimal2[MAX];
long int l=0;

printf("\n\nEnter any hexadecimal number: ");
scanf("%s",hexaDecimal2);

printf("\nEquivalent binary value: ");
while(hexaDecimal2[l]){
switch(hexaDecimal2[l]){
case '0': printf("0000"); break;
case '1': printf("0001"); break;
case '2': printf("0010"); break;
case '3': printf("0011"); break;
case '4': printf("0100"); break;
case '5': printf("0101"); break;
case '6': printf("0110"); break;
case '7': printf("0111"); break;
case '8': printf("1000"); break;
case '9': printf("1001"); break;
case 'A': printf("1010"); break;
case 'B': printf("1011"); break;
case 'C': printf("1100"); break;
case 'D': printf("1101"); break;
case 'E': printf("1110"); break;
case 'F': printf("1111"); break;
case 'a': printf("1010"); break;
case 'b': printf("1011"); break;
case 'c': printf("1100"); break;
case 'd': printf("1101"); break;
case 'e': printf("1110"); break;
case 'f': printf("1111"); break;
default: printf("\nInvalid hexadecimal digit %c ",hexaDecimal2[l]);
}
l++;
}

printf("\n\n-----------------------------");
printf("\n-----------------------------");
}

void hextooct()
{

int m;
printf("\n\nEnter the Hax number: ");
scanf("%x",&m);
printf("\nOctal equivalent of number is %o",m);
printf("\n\n-----------------------------");
printf("\n-----------------------------");
}
 

zegulas

Traceur
People here would be able to better help you if you explain to them what problem you are facing.
 
Top Bottom