Question
Write a C program to convert numbers between different numbering system. Allow user to choose within decimal, octal, and hexadecimal system. A starting code is
Write a C program to convert numbers between different numbering system. Allow user to choose within decimal, octal, and hexadecimal system.
A starting code is given. You can use it or start with your own design.
Test with different original number systems and desired systems.
#include
#include
void clearInputBuffer(); int main(void)
{ puts("Number Converter");
char userChoiceOriginal = ' ';
char userChoiceDesired = ' ';
int numberToConvert = 0;
puts("Please choose the original number system, d for Decimal, o for Octal, h for Hex:");
scanf("%c", &userChoiceOriginal);
clearInputBuffer();
switch(userChoiceOriginal){ case 'd': printf("Please enter decimal number: ");
scanf("%d", &numberToConvert);
clearInputBuffer();
break;
case 'o': printf("Please enter octal number: ");
scanf("%o", &numberToConvert);
clearInputBuffer();
break;
case 'h': printf("Please enter hexadecimal number: ");
scanf("%x", &numberToConvert);
learInputBuffer();
break;
default: puts("Incorrect input. Bye!");
return 0;
} //Ask for desired output system and then display accordingly
return 1;
}
void clearInputBuffer(){ char ch; while((ch = getchar()) != ' ');
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started