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.
Convert Hex to dec or Octal
Ancient Dragon commented: Nice program, too bad you used such an old obsolete compiler. +24
//****************************************************************************//
// //
// 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;
switch(choise)
{
case 1: clrscr();
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: clrscr();
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: clrscr();
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: clrscr();
cout << "Program terminated by user...";
exit(0);
break; //Unreachable code....
default : clrscr();
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;
}
herge 0 Newbie Poster
desai22982 0 Newbie Poster
guntime 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Naveed Marwat 0 Newbie Poster
messr135 0 Newbie Poster
karley 0 Newbie Poster
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.