wwwolf
2005-04-03 01:28:18 UTC
I'm trying to make a number conversion program but can't get it to compile
because it states that bin is undeclared. std::oct and std::hex are not
producing any compilation errors. If std::bin is not standard, then how do I
convert varaibles to binary code?
Oh, and if you see any novice mistakes then please tell me. I will probably make
this into a function later ( for my next self-assignment ) but I wanted to get
it working first.
Thanx for your help.
::::::::::::::::::::::::::::::::::::::::::
// My first number conversion program
#include <iostream>
int main()
{
// using statements in ABC order
using std::bin;
using std::cin;
using std::cout;
using std::flush;
using std::hex;
using std::oct;
long num;
int choice;
while(1)
{
cout << "\nEnter a decimal number ( 0 to quit ): " << flush;
cin >> num;
{
if ( num == 0 )
break;
else
{
cout << " Select a conversion choice...(1)bin, (2)oct, (3)hex : " <<
flush;
cin >> choice;
{
if ( choice == 1 )
cout << bin << num << flush;
else if ( choice == 2 )
cout << oct << "0" << num << flush;
else if ( choice == 3 )
cout << hex << "0x" << num << flush;
else if ( choice > 3 )
cout << "\n You don't follow directions very well do you?" <<
flush;
}
}
}
}
return 0;
}
::::::::::::::::::::::::::::::::::::
because it states that bin is undeclared. std::oct and std::hex are not
producing any compilation errors. If std::bin is not standard, then how do I
convert varaibles to binary code?
Oh, and if you see any novice mistakes then please tell me. I will probably make
this into a function later ( for my next self-assignment ) but I wanted to get
it working first.
Thanx for your help.
::::::::::::::::::::::::::::::::::::::::::
// My first number conversion program
#include <iostream>
int main()
{
// using statements in ABC order
using std::bin;
using std::cin;
using std::cout;
using std::flush;
using std::hex;
using std::oct;
long num;
int choice;
while(1)
{
cout << "\nEnter a decimal number ( 0 to quit ): " << flush;
cin >> num;
{
if ( num == 0 )
break;
else
{
cout << " Select a conversion choice...(1)bin, (2)oct, (3)hex : " <<
flush;
cin >> choice;
{
if ( choice == 1 )
cout << bin << num << flush;
else if ( choice == 2 )
cout << oct << "0" << num << flush;
else if ( choice == 3 )
cout << hex << "0x" << num << flush;
else if ( choice > 3 )
cout << "\n You don't follow directions very well do you?" <<
flush;
}
}
}
}
return 0;
}
::::::::::::::::::::::::::::::::::::