首页 > 代码库 > waiting time-计算等待时间之后的时刻
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-计算等待时间之后的时刻
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。