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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!