Part IV: Convert from a floating point hexaicosadecimal number to a double
The next step is to expand our hexaicosadecimal converter to take not just natural numbers, but floating point (a/k/a rational) numbers. The good news is that you're already halfway done, with your work from the previous section!
What you need to do is wrap your code from the previous section in an if-else block. IF (the input string does not contain a decimal point), do exactly what you did before. IF (the input string DOES contain a decimal point), do what you did before, except where your code had "the length of the whole string”, you'll instead need "the length of the part of the string that comes before the decimal point." That will get you the whole number part of the number. Then you'll need a second loop that looks just at the part of the string that is to the right of the decimal point, and adds those values into the accumulator. (Hint: Negative exponents correspond to dividing instead of multiplying. That is, 10-1 = 0.1 and 26-1 = 0.03846, 10-2 = 0.01 and 26-1 = 0.001479, and so on.)
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.