| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 689 人关注过本帖
标题:下面程序的if语句转switch语句问题
取消只看楼主 加入收藏
拉C
Rank: 1
来 自:南方
等 级:新手上路
帖 子:55
专家分:1
注 册:2008-7-29
结帖率:72.73%
收藏
已结贴  问题点数:10 回复次数:2 
下面程序的if语句转switch语句问题
if语句代码:
#include"iostream.h"
void main()
{
    char c;
    while(true)
    {
        cout<<"MAIN MENU:"<<endl;
        cout<<"l: left,r:right,q:quit ->";
        cin>>c;
        if(c == 'q')
            break;
        if(c=='l')
        {
            cout<<"LEFT MENU:"<<endl;
            cout<<"select c or d:";
            cin>>c;
            if(c=='c')
            {
                cout<<"you chose 'c'"<<endl;
                continue;
            }
            if(c=='d')
            {
                cout<<"you chose 'd'"<<endl;
                continue;
            }
            else
            {
                cout<<"you didn't choose c or d!"<<endl;
                continue;
            }
        }
        if(c=='r')
        {
            cout<<"RIGHT MENU:"<<endl;
            cout<<"select a or b:";
            cin>>c;
            if(c=='a')
            {
                cout<<"you chose 'a'"<<endl;
                continue;
            }
            if(c=='b')
            {
                cout<<"you chose 'b'"<<endl;
                continue;
            }
            else
            {
                cout<<"you didn't choose c or d!"<<endl;
                continue;
            }
        }
        cout<<"you must type l or r or q!"<<endl;
    }
    cout<<"quitting menu..."<<endl;
}
我转换的switch语句代码:
#include<iostream.h>
void main()
{
    char c;
    while(true)
    {
        cout<<"MAIN MENU:"<<endl;
        cout<<"l:left, r:right, q:quit ->";
        cin>>c;
        switch(c)
        {
        case'q':break;
        case'l':cout<<"LEFT MUNU:"<<endl;
            cout<<"selesct c or d:";
            cin>>c;
            switch(c)
            {
            case'c':cout<<"you chose'c'"<<endl;continue;
            case'd':cout<<"you chose'd'"<<endl;continue;
            default:cout<<"you didn't choose c or d:"<<endl;continue;
            }
            case'r':cout<<"RIGHT MUNU:"<<endl;
                cout<<"select a or b:";
                cin>>c;
                switch(c)
                {
                case'a':cout<<"you chose 'a'"<<endl;continue;
                case'b':cout<<"you chose 'b'"<<endl;continue;
                default:cout<<"you didn't choose c or d!"<<endl;continue;
                }
                default:cout<<"you must type l or r or q!"<<endl;
        }
        cout<<"quitting menu..."<<endl;
    }
}
主要问题是输入q时,不能退出菜单quitting menu..
麻烦告诉我错在哪里,顺利帮我修正一下。
而且问题不止这一个,谁能帮我编个正确的,万分感谢。


[ 本帖最后由 拉C 于 2010-6-2 14:50 编辑 ]
搜索更多相关主题的帖子: switch 语句 
2010-06-02 14:42
拉C
Rank: 1
来 自:南方
等 级:新手上路
帖 子:55
专家分:1
注 册:2008-7-29
收藏
得分:0 
回复 2楼 ciweitou163
不行,


新手新手,好好学习,多多指教,
2010-06-03 13:54
拉C
Rank: 1
来 自:南方
等 级:新手上路
帖 子:55
专家分:1
注 册:2008-7-29
收藏
得分:0 
回复 4楼 bccn250
试过了,不行啊。

新手新手,好好学习,多多指教,
2010-06-06 01:45
快速回复:下面程序的if语句转switch语句问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017291 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved