Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 625|回复: 3
打印 上一主题 下一主题

c++ : 以通话时间收费 (制作问题)

[复制链接]
NelsonG 该用户已被禁止
跳转到指定楼层
1#
发表于 2013-11-30 09:10 PM |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽
收藏收藏0

29

主题

1

好友

1487

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

2#
发表于 2013-11-30 09:54 PM |只看该作者
  else 里面再开多一个if
                {
                    cost=minutes*.25;
                }


回复

使用道具 举报

2

主题

0

好友

66

积分

中级会员

Rank: 2Rank: 2

3#
发表于 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 该用户已被禁止
4#
发表于 2013-12-2 04:51 PM |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2025-4-21 10:49 AM , Processed in 0.101471 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部