When you run a program and the first choice shows nothing, it's safe to say it's lacking! :)
I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.
Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.
#include <stdio.h>
int main() {
int ctr, bin, quotient, deci=0, binary,octal,hexa, gar;
float rem;
char mark_magic;
do {
clrscr();
quotient = 1;
binary = 1;
gotoxy(32,3); printf("-=< MAIN MENU >=-");
gotoxy(15,5); printf("from any Number System to Decimal System conversion");
gotoxy(5,6); printf("------------------------------------------------------------------------");
gotoxy(5,7); printf("------------------------------------------------------------------------");
gotoxy(26,9); printf("[A] Binary System");
gotoxy(26,11); printf("[B] Octal System");
gotoxy(26,13); printf("[C] Hexadecimal System");
gotoxy(26,15); printf("[X] Exit");
gotoxy(26,21); printf("what's your choice?: ");
mark_magic = getche();
clrscr();
switch(toupper(mark_magic)) {
case 'A':
clrscr();
gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########");
gotoxy(5,6); printf("------------------------------------------------------------------------");
gotoxy(5,7); printf("------------------------------------------------------------------------");
binary = 2;
gotoxy(28,9);printf("enter decimal number: ");
scanf("%d",&deci);
quotient = deci / binary;
gotoxy(28,11);printf("Equivalent in Binary is ");
for(bin=1; bin <=16; bin++) {
printf("%d",deci % 2);
deci = deci / 2;
}
gotoxy(51,24); printf("press any key to exit: ");
getche();
clrscr();
break;
case 'B':
clrscr();
gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########");
gotoxy(5,6); printf("------------------------------------------------------------------------");
gotoxy(5,7); printf("------------------------------------------------------------------------");
octal = 8;
gotoxy(28,9);printf("enter decimal number: ");
scanf("%d",&deci);
for (ctr = 1; ctr<=deci; ctr++)
quotient = deci / octal;
gotoxy(28,11);printf("Equivalent in Octal is %d",quotient);
gotoxy(51,24); printf("press any key to exit: ");
getche();
break;
case 'C':
clrscr();
gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########");
gotoxy(5,6); printf("------------------------------------------------------------------------");
gotoxy(5,7); printf("------------------------------------------------------------------------");
hexa = 16;
gotoxy(28,9);printf("enter decimal number: ");
scanf("%d",&deci);
for (ctr = 1; ctr<=deci; ctr++)
quotient = deci / hexa;
gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient);
gotoxy(51,24); printf("press any key to exit: ");
getche();
break;
}
}while(toupper(mark_magic) != 'X');
gar = getchar(); gar++;
return 0;
}
/*this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem?
thanks a lot!
*/ Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185