Your new program will first display a welcome banner, with a brief description of how it works and what it does. Next, your program gets an integer base (between 2 and 10 inclusive) and at most 6 character digits from its user. Finally, your program converts the given number in the given base to its base 10 equivalent and display a reasonable report.
To do this your program must:
Prompt the user to enter an integer base:
The base entered is checked for validity, is it between 2 and 10 inclusive?
An invalid (out of range) base forces the user into a re-entry loop, the user re-enters the base until it is valid.
Prompts the user to enter character digits, until they have entered a maximum of six, or have entered a non-digit character:
Each character entered is checked for validity, is it a character digit ['0', '9'] and is its equivalent integer digit less than the integer base?
An invalid character input prompts the user to choose between:
A re-entry loop, the user re-enters the character until it is valid.
Quit the character digit entry, and go to the report.
Requirements:
Your program must conduct all user input and output from the main function.
You must write a corresponding function prototype for each of the following function definitions.
bool isDigit(char c)
{
return ((c >= '0') && (c <= '9'));
}
Returns true if c is between '0' and '9' inclusive, otherwise returns false
int digit2Int(char c)
{
return (c - '0');
}
Given that c is between '0' and '9' inclusive, returns the corresponding integer between 0 and 9.
You must write a corresponding function definition the following function prototypes:
void welcome();
Displays a welcome banner, with a brief description of how it works and what it does.
int isValidDigit(char c, int base);
Returns the equivalent integer digit of c if c is a character digit ['0', '9'] and is its equivalent integer digit is strictly less than base, otherwise returns -1.
Note: This function must make use of the isDigit and digit2Int functions from above.
Hint(s):
It may be easiest to obtain the digits from right to left (least significant to most significant) this time. Then each digit (0 - 5) is multiplied by the base to that power and added to an accumulator.
You may find a boolean flag to be convenient to terminate the digit input loop when a sentinel (bad digit) is entered.
Sample run(s):
grid2: sample12
-----------------------------------------------------
Welcome to the CS201 exam base conversion program
-----------------------------------------------------
You will first be asked for the base of your number
which must be between 2 and 10 inclusive.
Next You will repeatedly be asked to enter the digits
of your number (right to left). If you enter a
non-digit you will be given the opertunity to either
re-enter the mistaken digit or quit the data entering
and proceed to the report.
------------------------------------------------------
Please enter the number's base [2, 10] : 1
Please enter the number's base [2, 10] : 11
Please enter the number's base [2, 10] : 2
Please enter digit 0 [0, 1] : 0
Please enter digit 1 [0, 1] : 1
Please enter digit 2 [0, 1] : 0
Please enter digit 3 [0, 1] : 1
Please enter digit 4 [0, 1] : 4
Invalid digit!
Do you wish to re-enter digit 4 (y | n) ? n
The resulting number in base 10 = 10
grid5: sample12
-----------------------------------------------------
Welcome to the CS201 exam base conversion program
-----------------------------------------------------
You will first be asked for the base of your number
which must be between 2 and 10 inclusive.
Next You will repeatedly be asked to enter the digits
of your number (right to left). If you enter a
non-digit you will be given the opertunity to either
re-enter the mistaken digit or quit the data entering
and proceed to the report.
------------------------------------------------------
Please enter the number's base [2, 10] : 5
Please enter digit 0 [0, 4] : 2
Please enter digit 1 [0, 4] : g
Invalid digit!
Do you wish to re-enter digit 1 (y | n) ? y
Please enter digit 1 [0, 4] : 1
Please enter digit 2 [0, 4] : 2
Please enter digit 3 [0, 4] : q
Invalid digit!
Do you wish to re-enter digit 3 (y | n) ? n
The resulting number in base 10 = 57
grid3: sample12
-----------------------------------------------------
Welcome to the CS201 exam base conversion program
-----------------------------------------------------
You will first be asked for the base of your number
which must be between 2 and 10 inclusive.
Next You will repeatedly be asked to enter the digits
of your number (right to left). If you enter a
non-digit you will be given the opertunity to either
re-enter the mistaken digit or quit the data entering
and proceed to the report.
------------------------------------------------------
Please enter the number's base [2, 10] : 3
Please enter digit 0 [0, 2] : 2
Please enter digit 1 [0, 2] : 1
Please enter digit 2 [0, 2] : 2
Please enter digit 3 [0, 2] : 1
Please enter digit 4 [0, 2] : 2
Please enter digit 5 [0, 2] : 1
The resulting number in base 10 = 455