佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1153|回复: 1

c++ : 以通话时间收费

[复制链接]
发表于 29-11-2013 10:46 PM | 显示全部楼层 |阅读模式
问题如下:

Write a program that computes the cost of along-distance call. The cost of the call is determined according to thefollowing rate schedule:
  • Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is     billed at a rate of $0.40 per minute.
  • Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is     charged at a rate of $0.25 per minute.
  • Any call started on Saturday or Sunday is charged     at a rate of $0.15 per minute.
The input will consist of
-         theday of the week
-         thetime the call started
-         thelength of the call in  minutes
The output will be the cost of the call.The time is to be input in 24-hour notation (e.g. the time 1:30 P.M. is input as 13:30). The day of the week will be read asone of the following pairs of character values, which are stored in twovariables of type char:
Mo       Tu        We       Th        Fr        Sa        Su
Be sure to allow the user to use eitheruppercase or lowercase letters or a combination of the two. The number ofminutes will be input as a value of type int.Your program should include a loop that lets the user repeat this calculationuntil the user says she or he is done.


我试过的答案是:

#include <iostream>
using namespace std;
int main()
{
        int start_time, minutes;
        double cost;
        char first, second, choice('Y');
        do
        {
            cout<<"When did the call start?\n";
            cout<<"Please enter the time in 24-hour notation.\n";
            cin>>start_time;
            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;
     
            if ((((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'))))
            {
                if ((start_time>=800)||(start_time<=1800))
                {
                    cost=minutes*.40;
                }
                else
                {
                    cost=minutes*.25;
                }
            }
           
            else if ((((first=='S')||(first=='s'))&&((second=='A')||(second=='a'))) || (((first=='S')||(first=='s'))&&((second=='U')||(second=='u'))))
            {
                cost=minutes*.15;
            }

            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;
}

但依旧不完整,因为:
1. 无法从 59分钟跳到 00分钟
2. 不能同时包含两天的通话时间(比如从星期五的11.00pm打到星期六1.00am是两小时,而这两小时却只算在星期五)

请问有什么解决方法?另外这是否和<chrono>有关?   


回复

使用道具 举报


ADVERTISEMENT

发表于 6-1-2014 12:01 PM | 显示全部楼层
requirement只'started'..所以1和2不用做....
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 11-9-2025 11:27 PM , Processed in 0.117243 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表