600.120 Intermediate Programming
Spring 2009 -- Assignment 2
Due Wednesday, 2/11 by 2:45pm

The goal for this week is to do structured programming in C, using functions and pointers to organize processing and update data.

The Problem:

Write a program (in file pg2.c) that can be used to convert numbers from one base to another. In order to make it easier to test your program (and, hint hint, to write it), always output the original value as a decimal (base 10) also, even if it is not requested. If a requested base b is <= 10, then it uses the digits 0 through b-1. When a base is >10, then it also uses the lower case letters of the alphabet as digits. For example, something in base 20 would use digits 0-9 and letters a-j, corresponding to values 10-19. You are also required to do error checking on the input and stop processing when an error occurs, displaying a relevant error message. Your program is required to work (and should error check these inputs also) for bases 2 through 36. Here are some sample runs:

Enter original base: 13
Enter number in base 13: a3b50
(Decimal value is 294125)
Enter desired base: 6
Converted value is 10145405

Enter original base: 4
Enter number in base 4: 123456
ERROR: invalid characters in number

Enter original base: 4
Enter number in base 4: 2031
(Decimal value is 141)
Enter desired base: 1b6
ERROR: invalid base input

Implementation Details:

Reflection: Are there any restrictions on the values that your solution will process correctly? If so, what and why? Could you eliminate the problem without violating the implementation details? Discuss in a comment at the start of your program.