switch用法

switch用法

#include<iostream>
using namespace std;
int main()
{
    bool quit = false;//flage for quitting 
    while (quit == false)
    {
        cout << "Select a,b,c or q to quit: ";
        char response;
        cin >> response;
        switch (response)
        {
                case 'a': cout << "you chose 'a" << endl;
                         break;
                case 'b': cout << "you chose 'b'" << endl;
                         break;
                case 'c': cout << "you chose 'c'" << endl;
                         break;
                case 'q': cout << "quitting menu" << endl;     
                         quit = true;
                         break;
                default: cout << "please use a,b,c or q!" << endl;
        }
    }
}

 

posted @ 2016-07-25 14:38  hopskin1  阅读(125)  评论(0编辑  收藏  举报