JBTALKS.CC

标题: c++ : 以通话时间收费 (制作问题) [打印本页]

作者: NelsonG    时间: 2013-11-30 09:10 PM
提示: 作者被禁止或删除 内容自动屏蔽
作者: SwaiLspongebob    时间: 2013-11-30 09:54 PM
  else 里面再开多一个if
                {
                    cost=minutes*.25;
                }
作者: karkit1990    时间: 2013-12-1 12:23 AM
本帖最后由 karkit1990 于 2013-12-1 12:39 AM 编辑

我写了一个,不过我没有test过的,你试一下看能用吗

#include<iostream>
using namespace std;

int main()
{
        int startTime,endTime,weekday,weekend,hrs,min,minutes;
        double cost;
        char first, second, choice;

        do
        {
                do
                {
                        cout<<"When did the call start?\n";
                            cout<<"Please enter the time in 24-hour notation.\n";
                            cin>>startTime;
                            cout<<"How long did the call last?\n";
                            cin>>minutes;
                            cout<<"Please enter the first two letters of the day of the call.\n";
                            cin>>first>>second;
                } while ((((first!='M')||(first!='m'))&&((second!='O')||(second!='o'))) || (((first!='T')||(first!='t'))&&((second!='U')||(second!='u'))) || (((first!='W')||(first!='w'))&&((second!='E')||(second!='e'))) || (((first!='T')||(first!='t'))&&((second!='H')||(second!='h'))) || (((first!='F')||(first!='f'))&&((second!='R')||(second!='r'))) || (((first!='S')||(first!='s'))&&((second!='A')||(second!='a'))) || (((first!='S')||(first!='s'))&&((second!='U')||(second!='u'))));


                if ((first=='M')||(first=='m')||(first=='T')||(first=='t')||(first=='W')||(first=='w')||(first=='T')||(first=='t')||(first=='F')||(first=='f'))
                {
                        if ((startTime>=800)&&(startTime<=1800))
                                    cost=minutes*.40;
                        else
                                    cost=minutes*.25;
                }
                else
                        cost=minutes*0.15;


                if ((first=='F')||(first=='f'))
                {
                        hrs = minutes / 60 * 100;
                        min = minutes % 60;
                        endTime = starTime + hrs + min;

                        if (endTime > 2400)
                        {
                                weekday = ((2400 - startTime) / 100 * 60 ) * .25;
                                weekend = ((endTime - startTime) / 100 * 60)*.15;
                                cost = weekday + weekend;
                        }
                }

                if ((first=='S')||(first=='s')) && ((second=='U')||(second=='u'))
                {
                        hrs = minutes / 60 * 100;
                        min = minutes % 60;
                        endTime = starTime + hrs + min;

                        if (endTime > 2400)
                        {
                                weekday = ((endTime - startTime) / 100 * 60 ) * .25;
                                weekend = ((2400 - startTime) / 100 * 60)*.15;
                                cost = weekday + weekend;
                        }
                }

                cout<<"The cost of the call is "<<cost<<".\n";
                cout<<endl;
                    cout<<"Do you want to rerun the program? Y or N\n";
                    cin>>choice;
                    cout<<endl;                               
        }while ((choice=='Y')||(choice=='y'));

        return 0;
}
作者: NelsonG    时间: 2013-12-2 04:51 PM
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5