C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 8th, 2005, 08:50 AM
infinity infinity is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 infinity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 27 sec
Reputation Power: 0
Newbie simple program issue

Hi,

i have a problem with a simple section of programming i am writing. I am using console in and out (still new to C++ )


Code:
int main(void) 
{
    int choice = 0;
	do//Menu loop//
	{
    
    cout << "xxxxxxxxxxx...........\n";
    cout << "xxxxxxxxxxx(enter corresponding number):";
    cout << "\n"; 
    
    cout << "1. xxxx\n";
    cout << "2. xxxx\n";
    cout << "3. xxxx\n";
    cout << "\n"; 
   
int choice ;
    
	cout << "Enter choice:";
	cin >> choice;
 
    }
	while (choice < 0 ||choice > 4);//loop conditions//
	{
   
switch (choice)
{
    case 1:
           cout << "Opening port, press power shortly" << endl;
    break;

    case 2: 
           cout << "Opening port, press power shortly" << endl;
    break;

    case 3: 
           cout << "Opening port, press power shortly" << endl;
    break;  
    
    default:
           cout<<"Invalid option!" <<endl;
    break;     
    }  
    
    return 0; }


As you can see, i have just include the switch options not their functions.

program compiles perfectly and runs. But when i get to the stage where i have to enter in a "choice" either 1, 2 or 3 i do so and hit enter but the program exits without errors. Surely Opening port, press power shortly should be output?

Really doing my head in, sure the answer is sooooooooo obvious but not for newbiw like me

Many thanks people

Reply With Quote
  #2  
Old August 8th, 2005, 05:22 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Smile pausing program

I think this might answer your question, just before the return 0 at the bottom put either==>

cin.get();

system("PAUSE");

or just declare another variable at the top and put another

cin>>statement;

all of these should work in pausing the program until the user enters some form of information, depending on what compiler you are using. If you are using an older compiler you will need to include the library #include <stdlib.h> at the top to use system(). Hope this helps ya out a little =Þ

OH ya, and in your "while" condition I would probably use a 1 rather than 0 because if you set it to less than 0 the user can still enter a 0 and be correct but just a thought try it out and see what you get =Þ both ways and youll see what I mean.

Reply With Quote
  #3  
Old August 8th, 2005, 07:47 PM
infinity infinity is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 infinity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 27 sec
Reputation Power: 0
Thankyou very very much. Legend

Reply With Quote
  #4  
Old August 8th, 2005, 10:27 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
np anytime I can help, which isnt very often =) Just a newb myself.

GeO

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Newbie simple program issue


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT