Question: Part-1 Write a program that loops. At each loop iteration, the program prompts the user to input a value for the base b (b could

 Part-1 Write a program that loops. At each loop iteration, the

program prompts the user to input a value for the base b

(b could be any value from 2 to 10), then a string

Part-1 Write a program that loops. At each loop iteration, the program prompts the user to input a value for the base b (b could be any value from 2 to 10), then a string of characters that represent a number in base b. The program then converts the number to a decimal representation, and prints the result. For example, if the user types the string "15", and the base is b 8, the program will convert it to 13 in decimal and print 13. The max number of characters accepted by the program is MAX NO CHARACTERS. The program exits the loop when the user types the value -1 for the base Your program must meet the below requirements: You must read the input number as a string of characters. You are not allowed to read as an integer ne ea edit owever an charString, int numberChars, int basel); Arguments: name of a char array that contains the characters representing the number, number of characters (digits) of the number and the base. The first element of the array is the most significant digit of the number Return: the number in decimal, as a long int. In the extra credit version, the function does input validation as described below and returns-1 if the input is not valid Notes For your program, you can assume the value of MAX NO CHARACTERS is set by a variable constant. Set it to 10 Assume the user does not type more than MAX NO_CHARACTERS characters. Hints: You may need to use the (int) operator to get the ASCII code of a character. The syntax is myCode = (int) myChar; //the ASCII code of myChar is assigned to myCode You may need to use %n in scant to determine the number of characters typed At some point in the program, you may need to loop over the characters typed, and a suggestion is to use the "for" loop. The "for" loop in C is like in C++ o o o Pseudocode for the basic version Define an array of char, called charArray Define an int called numberTyped Prompt the user to input the base b While (base b not equal -1) Prompt the user to input the number Read the number into charArray and the number of characters typed into numberTyped, using the appropriate scanf specifiers Call function convertToDecimal

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!