I am suppose to create program that displays decimals in hex,dec and oct form using stream manipulators . i think i got right (can't check since my visual studios is not working
#include <iostream>
#include <conio.h>
#include <iomanip>
using std::dec;
using std::hex;
using std::oct;
int main()
{
int number = 1;
while (number <= 256)
{
std::cout << std::dec << number << "\t";
std::cout << std::hex << number << "\t";
std::cout << std::oct << number << "\n";
number++;
}
_getch();
}
You could turn your while loop into a for loop to shorten the code and improve clarity.
Also, you don't need to write std:: in front of dec/hex/oct as you've brought them into scope with your using declarations.
Use std::showbase to make output more obvious.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <iomanip>
using std::dec; using std::hex; using std::oct;
using std::showbase;
using std::cout;
int main()
{
cout << showbase;
for( int number = 1; number <= 256; number++ ) {
cout << dec << number << "\t";
cout << hex << number << "\t";
cout << oct << number << "\n";
}
}