Additional Digits after decimal to Octal/hex/char conversions

Hey guys.

So for my home work assignment we were asked to make four columns of data where there is the decimal, octal, hex, and character equivalents of the letters a-z.

Here is my current code:

#include <iostream>
#include <stdlib.h>
#include <iomanip>

using namespace std;



int // introduce the main program
main()
{
int var; // Introduce var1 as a varrible
var=65; // Set inital value of var1 to be 65

cout.setf(cout.left);
cout << setw(10); // Set Width to 10 Characters
cout << "Decimal"; // "Decimal" Column Title
cout << setw(10); // Set Width to 10 Characters
cout << "Octal"; // "Octal" Column Title
cout << setw(10); // Set Width to 10 Characters
cout << "Hex"; // "Hex" Column Title
cout << setw(10); // Set Width to 10 Characters
cout << "Char"; // "Char" Column Title
cout.setf(cout.left);
cout << "\n";

for (int i = 1; i <=26; i++) // For Loop: Run the loop 26 times.
{
int printf( const char *format, ... );
cout.setf(cout.left); // Left Justification
cout << setw(10); // Set Width to 10 Chracters
cout << var; // Display var (Decimal)
cout.setf(cout.left); // Left Justification
cout << setw(7); // Set Width to 10 Chracters
cout << printf("%-o",var); // Display var as an Octal Number
cout.setf(cout.left); // Left Justification
cout << setw(8); // Set Width to 10 Chracters
cout << printf("%-X",var); // Display as a Hexidecimal Number
cout.setf(cout.left); // Left Justification
cout << setw(7); // Set Width to 10 Chracters
cout << printf("%-c",var); // Display as an Alphabetical Chracter
cout << "\n"; // Begin a new line
var = var+1; // Increase the value of var by one
}
Return:0;
}

and when I run the program I get the following:



Decimal Octal Hex Char
65 1013 412 A1
66 1023 422 B1
67 1033 432 C1
68 1043 442 D1
69 1053 452 E1
70 1063 462 F1
71 1073 472 G1
72 1103 482 H1
73 1113 492 I1
74 1123 4A2 J1
75 1133 4B2 K1
76 1143 4C2 L1
77 1153 4D2 M1
78 1163 4E2 N1
79 1173 4F2 O1
80 1203 502 P1
81 1213 512 Q1
82 1223 522 R1
83 1233 532 S1
84 1243 542 T1
85 1253 552 U1
86 1263 562 V1
87 1273 572 W1
88 1303 582 X1
89 1313 592 Y1
90 1323 5A2 Z1


The problem is at the end of the Octal Number I have a "3" a "2" at the end of the Hex, and a "1" after the Char output.

Any Ideas?
cout << printf ????

You got that far without code tags? You are a better man than me, jsmith.
Topic archived. No new replies allowed.