![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 10
Rep Power: 0
![]() |
First Programm in C++ - Convert Hex Dec Oct -Ant comment Pls
//**************************************
//
// Program Name : ConvDec.cpp
//
// Programmer : Vagabond
// Beginner C++
//
// Description : The user is asked to in
// put 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 bythe Escape key after
// each convertion.
//
// Compiler : Borland Turbo C++ v4.5.
// Date : 16/03/2006
//
//**************************************
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
const int ESC = 27;
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 << "\nvalue 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;
} |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Looks great. Little tip: put the clrscr(); function call before the switch, instead of having it at the top of each case.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 10
Rep Power: 0
![]() |
Thanx - I see your point too much unnecessary repition.
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
No probs. Again, nice work.
|
|
|
|
|
|
#5 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 639
Rep Power: 4
![]() |
Also instead of using iostream.h, use the more modern iostream
Like this: #include <iostream> You will now be faced with namespaces. You can either specify the namespace of functions and methods with the scope resolution operator (for example, std::cout), or place a using directive at the beginning of your code: using namespace std;
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2006
Posts: 10
Rep Power: 0
![]() |
Yeh! I would but my modern Turbo C++ won't allow it.
#include <iostream> using namespace std; I know! I know...... but my reasons are posted at the end ot this thread. http://www.programmingforums.org/for...ead.php?t=8927 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|