注册 登录
编程论坛 C++教室

一道初学者的题目 模拟出租车(HELP)

leehao 发布于 2010-03-13 16:21, 715 次点击
现在出发吗?
yes                              //此处输入yes后开始执行
现在出行(M):42332             //此处输入出行距离
出行开始--
<<<<<                            //模拟前进 <等于10M 一行最多画10个<        

....                            // 省略。。太多了。。

出行结束:4233200元



题目如上
#include <iostream>
#include <string>
using namespace std;

int main()
{
    long a,b,c,d,e,f,h;

    string g="yes",s;

    cout <<"现在出发吗?"<<endl;
    cin>>s;
   
    if(s=="yes")
    {
        cout <<"现在出行(M):";
        cin >> a;
        cout <<"出行开始--"<<endl;
        b=a/10;
        c=a/100;
        d=b%10;
        if(c<=1)
        {
            for(e=0;e<b;e++)
            {
                cout<<">";
            }
        if(c>1)
                for (e=0;e<(c-1);e++)
                {
                    for (f=0;f<10;f++)
                        cout << ">";
                    cout<< endl;
                }
                for (e=0;e<b;e++)
                    cout << ">";
                cout <<endl;
        }
        h=a*100;
        cout <<"出行停止:"<<h<<"元"<<endl;


    }
    return 0;

}


这程序我写的 不对。。
高手帮助纠正下。。谢谢。。
菜鸟新人
6 回复
#2
floppyfuck2010-03-13 19:09
厉害! 这么个程序你出了错自己好好看书吧我就不
#3
cnfarer2010-03-13 20:26
一个循环就够了!用那么多干啥?
#4
leehao2010-03-13 21:31
我觉得应该需要。因为有很多种情况。。
有好心人帮我分析下程序吗
#5
cnfarer2010-03-14 13:00
回复 4楼 leehao
好多种情况是用分支而不是循环啊!
#6
hzh5122010-03-14 16:09
你程序写的太....

#include <iostream>
#include <string>
using namespace std;

int main()
{
    long distance,cost;
    string s;
    do
    {
        cout <<"    欢迎乘坐本出租车   Welcome"<<"\n"<<"现在出发吗?(yes/no)\n"<<endl;
        cin>>s;
        if(s=="yes"||s=="y")
        {
            cout <<"现在出行(M):";
            cin >> distance;
            cout <<"出行开始--"<<endl;
            for(int i=0;i<distance/10;i++)
            {
                if(i%10==0)
                    cout<<endl;
                cout<<'>';
            }
            cout<<endl;
            cost=distance*100;
            cout <<"出行停止:"<<cost<<"元"<<endl;
        }
    }while(s!="yes"&&s!="y");

    return 0;
}
#7
leehao2010-03-17 09:13
thank you!!!!
1