473,467 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Newbie. help with validity checks

8 New Member
How would i loop this switch statement if the user does not want to quit after running the selection, lets say 'S'. I tried a do while loop but it only causes errors. Thanks!

char choice;

do{
switch (choice)

{
case 'V': case 'v':
voltage ();
break;
case 'S': case 's':
rev_str();
break;
case 'Q': case 'q':
cout << "Program Terminated" << endl;
break;
default:
cout << "Invalid selection. Please try again" << endl;

}
} while (choice!='Q','q')
Oct 17 '06 #1
3 1442
arne
315 Recognized Expert Contributor
You may try:

Expand|Select|Wrap|Line Numbers
  1. int main( void )
  2. {
  3.     char choice;
  4.     bool quit = false;
  5.  
  6.     while( false == quit && cin >> choice ) {
  7.  
  8.         switch( choice ) {
  9.  
  10.             case 'S':
  11.                 cout << "Received " << choice << endl; 
  12.                 break;
  13.  
  14.             case 'q':
  15.             case 'Q':
  16.                 cout << "Quit ... " <<  endl; 
  17.                 quit = true;
  18.                 break;
  19.  
  20.             default:
  21.                 cout << "Invalid selection " << choice << endl; 
  22.                 break;
  23.         }
  24.  
  25.     }
  26.  
  27.     return 0;
  28. }
  29.  
Oct 17 '06 #2
Keo932
8 New Member
thanks buddy
Oct 17 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
} while (choice!='Q','q')
This line should be written as

} while (choice!='Q' && choice!='q');
Oct 17 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When...
4
by: Jekke, Just Jekke | last post by:
All-- SmptMail.Send will failover whenever the from address has a non-existent TLD. Is there any way to check for this before I actually call. Send? TIA --Jekke Brain for hire. E-mail at...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
1
by: dwelch91 | last post by:
c.l.p- I am undertaking writing an installer for a software package using Python. It is exclusively for Linux. Because this is an installer and has to run on numerous Linux distros, it is...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
9
by: AM | last post by:
Hi, I have a C++ Dll that has a function that is being exported as shown below extern "C" __declspec(dllexport) validationResult __stdcall _validateData(double dataToMat, int time); A...
3
newnewbie
by: newnewbie | last post by:
Have a nested IIF statement that works but returns wrong values....Here's the syntax: Expr3: IIf(=2 Or 3,'valid',IIf(=4,'invalid','unknown')) Needed: if validity is 2 or 3 = Valid, if...
5
by: mattmao | last post by:
Greetings everyone. The Newbie is coming back from uni... I knew making a good form validation JavaScript would be a piece of cake for you guys, but as a novice programmer as me, I still find...
3
by: Kai Schlamp | last post by:
Hello! In my schema I have the following: <xs:complexType name="textareaType"> <xs:simpleContent> <xs:restriction base="xs:string"> <xs:attribute ref="label" use="required" />...
3
by: Mike Copeland | last post by:
How do I work with a std::list that might have multiple objects having the same "key", but which have other data that is different? Here's code that compiles, but doesn't do quite what I expect:...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.