Waiting Time-calculate the time point after the wait time in the 24-hour format, and allow repeated calculation:
//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 "<
Result:
Current time,Enter the 24 hours time like 11:11 :12:30Wait time,Enter the 24 hours time like 11:11 :15:40After the waiting time,the time is 16:10Do you want again?yCurrent time,Enter the 24 hours time like 11:11 :8:30Wait time,Enter the 24 hours time like 11:11 :15:10After the waiting time,the time is 23:40Do you want again?
Waiting Time-calculate the time point after the waiting time