// Exercise Specifications: /** * Write a program called multi_input.cpp that prompts the user to enter * several integers in any combination of octal, decimal, or hexadecimal, * using the 0 and 0x base suffixes; interprets the numbers correctly; and * converts them to decimal form. Then your program should output the * values in properly spaced columns like this: * 0x43 hexadecimal converts to 67 decimal * 0123 octal converts to 83 decimal * 65 decimal converts to 65 decimal */ |
|
|
true
, the digit is not an octal or hexadecimal digit? Because as you can see, I'm trying to leverage that in my code. It won't be funny if it doesn't work that way. And is it correct to think that isdigit() checks for a decimal number, meaning that if it returns true, the digit is not an octal or hexadecimal digit? |
ike, maybe the user tries to fool the program by putting a 0 in front of a decimal number |
|
|
Please enter some numbers in any combination of decimal, hexadecimal, or octal. Use the 0x and 0 suffixes for hexadecimal and octal as needed. 0xac0 4561 015 0 in hexadecimal converts to 0 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal cccccccc in hexadecimal converts to -858993460 in decimal Please enter a character to exit Press any key to continue . . . |
|
|
0x45 in hexadecimal converted to decimal is 69 in decimal |
|
|
|
|
how to tell if a number is octal |
if
and for
in main
back into while
. Please enter some numbers in any combination of decimal, hexadecimal, or octal. Use the '0x' and '0' suffixes for hexadecimal and octal as needed. 0x45 0x45 in hexadecimal converts to 69 in decimal 045 56 0x74 045 in octal converts to 37 in decimal note: '045 56 0x74' was not fully parsed ^Z Please enter a character to exit k Press any key to continue . . . |
You could use std::getline if you want to handle an unlimited number of numbers. A std::istringstream would deal with all numbers flawlessly. |
|
|
I need to read the numbers in any combination of decimal, hexadecimal and octal, and then print them out in properly spaced columns where the numbers as they were entered are lined up with the originally entered numbers indented towards the left, then the name of the base with two spaces between it and the number, and then "converts to" all lined up in column and "<some number> decimal" lined up in one column. I can't get the output looking right. |
Use the manipulators std::setw(), std::left and std::right |
Please enter some numbers in any combination of decimal, hexadecimal, or octal. Use the '0x' and '0' suffixes for hexadecimal and octal as needed. 0x43 0123 65 852 0852 0xca 0x43 hexadecimal converts to 67 decimal 0123 octal converts to 83 decimal 0123 decimal converts to 83 decimal 0123 hexadecimal converts to 83 decimal 65 decimal converts to 65 decimal 65 hexadecimal converts to 65 decimal 852 decimal converts to 852 decimal 852 hexadecimal converts to 852 decimal 0852 octal converts to 0 decimal 0852 decimal converts to 0 decimal 0852 hexadecimal converts to 0 decimal 0xca hexadecimal converts to 202 decimal Please enter a character to exit k Press any key to continue . . . |
|
|
break
statements. I also have a problem of "no output" in Exercise 5, but I'll get to that later. Thanks for pointing that out, by the way.
|
|