码迷,mamicode.com
首页 > 其他好文 > 详细

waiting time-计算等待时间之后的时刻

时间:2014-09-01 02:54:32      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:waiting time-计算等待时间之后的时刻

waiting time-计算等待时间之后的时刻,按24小时制计算,允许重复计算:

//waiting time
#include<iostream>
using namespace std;

void get_time(int& hours,int& minutes);
void convert_time(int& currenthours,int& currentminutes,int& waithours,int& waitminutes);
//void show_time();

int main()
{
    int currenthours,currentminutes;
    int waithours,waitminutes;
    char ans;
    
    do{
        cout<<"Current time,";
        get_time(currenthours,currentminutes);
        cout<<"Wait time,";
        get_time(waithours,waitminutes);
        convert_time(currenthours,currentminutes,waithours,waitminutes);
    
        cout<<"Do you want again?";
        cin>>ans;
    }while(‘y‘ == ans || ‘Y‘ == ans);
    
    return 0;
}

void get_time(int& hours,int& minutes)
{
    char b;
    cout<<"Enter the 24 hours time like 11:11 :\n";
    cin>>hours>>b>>minutes;
}

void convert_time(int& currenthours,int& currentminutes,int& waithours,int& waitminutes)
{
    int hours,minutes;
    if(currenthours + waithours < 24)
        {
            hours = currenthours+waithours;
            if(currentminutes + waitminutes < 60)
                minutes = currentminutes + waitminutes;
            else 
                {
                    hours += 1;
                    minutes =(currentminutes + waitminutes) - 60;
                }
        }
    else 
        {
            hours = (currenthours+waithours) - 24 + currenthours;
            
            if(currentminutes + waitminutes < 60)
                minutes = currentminutes + waitminutes;
            else 
                {
                    hours += 1;
                    minutes =(currentminutes + waitminutes) - 60;
                }
        }
    
    cout<<"After the waiting time,the time is "<<hours<<":"<<minutes<<endl;    
    
    return;
    
}

结果:

Current time,Enter the 24 hours time like 11:11 :
12:30
Wait time,Enter the 24 hours time like 11:11 :
15:40
After the waiting time,the time is 16:10
Do you want again?y
Current time,Enter the 24 hours time like 11:11 :
8:30
Wait time,Enter the 24 hours time like 11:11 :
15:10
After the waiting time,the time is 23:40
Do you want again?


waiting time-计算等待时间之后的时刻

标签:waiting time-计算等待时间之后的时刻

原文地址:http://9320314.blog.51cto.com/9310314/1547073

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!