Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 19th, 2006, 12:54 PM   #1
Vagabond
Newbie
 
Vagabond's Avatar
 
Join Date: Mar 2006
Posts: 10
Rep Power: 0 Vagabond is on a distinguished road
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;
        }
Vagabond is offline   Reply With Quote
Old Mar 19th, 2006, 1:01 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Looks great. Little tip: put the clrscr(); function call before the switch, instead of having it at the top of each case.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 19th, 2006, 1:29 PM   #3
Vagabond
Newbie
 
Vagabond's Avatar
 
Join Date: Mar 2006
Posts: 10
Rep Power: 0 Vagabond is on a distinguished road
Thanx - I see your point too much unnecessary repition.
Vagabond is offline   Reply With Quote
Old Mar 19th, 2006, 1:58 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
No probs. Again, nice work.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 19th, 2006, 2:06 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 639
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline   Reply With Quote
Old Mar 19th, 2006, 2:30 PM   #6
Vagabond
Newbie
 
Vagabond's Avatar
 
Join Date: Mar 2006
Posts: 10
Rep Power: 0 Vagabond is on a distinguished road
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
Vagabond is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC