CJCoding With Joseph
15free / daySign inCreate account

Hex and Decimal

Write a function void printHexDec(ostream& out, int n) that writes n in decimal, then a space, an equals sign, a space and 0x, then n again in lowercase hexadecimal (no padding), then a newline — for 255 the line is 255 = 0xff, for 0 it is 0 = 0x0. Print the 0x prefix as a plain string, switch the stream to hex for the second number, and switch it back with dec before returning.

The test prints another integer (100) through the same stream right after the call (see Expected Output).

Do NOT write a main function.

Expected Output:

255 = 0xff
100
4096 = 0x1000
0 = 0x0
42

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Streamsostream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.