#include <iostream>
template < typename T >
inline T highbit(T& t)
{
return t = (((T)(-1)) >> 1) + 1;
}
template < typename T >
std::ostream& bin(T& value, std::ostream &o)
{
for ( T bit = highbit(bit); bit; bit >>= 1 )
{
o << ( ( value & bit ) ? '1' : '0' );
}
return o;
}
int main()
{
unsigned long value;
std::cout << "Enter number: " << std::endl;
std::cin>>value;
std::cout << "hex: " << std::hex << value << std::endl;
std::cout << "dec: " << std::dec << value << std::endl;
std::cout << "oct: " << std::oct << value << std::endl;
std::cout << "bin: ";
bin(value, std::cout);
std::cout << std::endl;
system("pause");
return 0;
}
its working verry well but...
i wanna change that and make this in swith case and all that stuff i started like that
#include <iostream>
#include <conio.h>
using namespace std;
float a,n;
char wybor;
int main(void)
{
system("cls");
cout << " Dziesietne na binarne oraz dziesietne na szesnastkowe :P " << endl;
cout<<"Podaj liczbe:";
cin>>a;
cout <<"Wybierz działanie: dziesietne na binarne(b),dziesietne na szesnastkowe(6)";
cin >> wybor;
switch(wybor)
{
case 'b' :{
string LongToBinary(long int n)
return n==0 ? "" : LongToBinary(n/2) + ((n%2)?"1":"0");
cout<<LongToBinary(a)<<endl;
}
break;
case '6':{
cout<< "Zapis szesnastkowy: "<< hex << a << endl;
}
};
getch();
}
but still i cant compile thet HELP!
im using devc++
and that stuff
//****************************************************************************//
// //
// Program Name : ConvDec.cpp //
// //
// Programmer : K.Angel //
// : Novice C++ //
// //
// Description : The user is asked to input a number in either Hex, Octal or //
// Decimal, which is then converted to Hex, Octal & Decimal. //
// The user can exit the program from the MAIN MENU or by //
// the Escape key after each convertion. //
// //
// Compiler : Borland Turbo C++ v4.5. //
// Date : 16/03/2006 //
// //
//****************************************************************************//
#include <iostream.h>
#include <conio.h> // for clrscr() & getche() functions...
#include <stdlib.h> // for exit() function...
const int ESC = 27; // Used for escape sequince
int main()
{
int key = 0;
int choise = 0;
long number;
while(key != ESC)
{
cout << "Choose Your Number Base\n";
cout << "\n\t1. Hexadecimal.";
cout << "\n\t2. Octal.";
cout << "\n\t3. Decimal.";
cout << "\n\t4. Exit.\n\t ";
cin >> choise;
clrscr();
switch(choise)
{
case 1:
cout << "Enter a Hex number: ";
cin >> hex >> number;
cout << "\n value in octal = "
<< oct << number << endl;
cout << " value in decimal = "
<< dec << number << endl;
break;
case 2:
cout << "Enter a Octal number: ";
cin >> oct >> number;
cout << "\n value in hex = "
<< hex << number << endl;
cout << " value in decimal = "
<< dec << number << endl;
break;
case 3:
cout << "Enter a dec number: ";
cin >> dec >> number;
cout << "\n value in octal = "
<< oct << number << endl;
cout << " value in hex = "
<< hex << number << endl;
break;
case 4:
cout << "Program terminated by user...";
exit(0);
break; //Unreachable code....
default :
cout << "ERROR ~ Invalid selection\n\n";
break;
}
cout << "Press any key to continue or 'Esc' to exit";
key = getche();
clrscr();
}
cout << "Program terminated by user...";
return 0;
}
is not working
i wanna do this in that switch and case.... but i cant please help if u can
and the other bigger problem is to make program that shows all possible moves of king on chess board i cant find in google that kind of stuff and need help
best regards
Speedy


Ask A New Question
Reply





MultiQuote






|