Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

escaping from a switch/loop

Posted on 2004-10-14
3
Medium Priority
?
248 Views
Last Modified: 2010-04-02
Hullo,

I've written a very simple switch inside a loop, it's basically :

  do {
  cout << "\n\nYour answer is :   ";
  cin >> letter;
  letter = toupper(letter);
  switch ( letter )
{
  case 'A': cout << "Incorrect.";
  break;
  case 'B': cout << "Correct.";
  break;
 } } while (letter);

It actually has a few more options, but I won't bore you with that . . The thing is, while this is going on, there's nothing the user can do to end the program.

How can I specify something for the user to type in that will let them escape this loop ?
0
Comment
Question by:drivensnow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12314658
do {
  cout << "\n\nYour answer is :   ";
  cin >> letter;
  letter = toupper(letter);
  switch ( letter )
{
  case 'A': cout << "Incorrect.";
  break;
  case 'B': cout << "Correct.";
  break;
 }
if(letter == 'Q')
break; // this break will jump out of the loop
 } while (letter);

welcome to www.fruitfruit.com
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 2000 total points
ID: 12314730
do {
      cout << "\n\nYour answer is :   ";
      cin >> letter;
      letter = toupper(letter);
      switch ( letter )
      {
            case 'A': cout << "Incorrect.";
            break;
            case 'B': cout << "Correct.";
            break;
            case 'Q': cout << "Bye.";  letter = 0;      
            break;
      }
} while (letter);
0
 

Author Comment

by:drivensnow
ID: 12316013
It works !  :D Thankee.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question