Answer:
Program to accept time as hour and minute:
#include<iostream>
using namespace std;
int main()
{
//declare variable to store hour and minutes.
int hour, min;
//enter hour and minutes.
cout<<"Enter Hour:"<<endl;
cin>>hour;
cout<<"Enter minutes:"<<endl;
cin>>min;
//In case (min + 15) is greater than 60, then add one in hour and find appropriate minutes.
if(min+15>=60)
{
hour = ++hour;
min = (min+15)-60;
}
else
min = min +15;
//display hour and min.
cout<<"Hour:"<<hour<<" Minutes:"<<min<<endl;
}
Output:
Enter Hour:
9
Enter minutes:
46
Hour:10 Minutes:1
Step-by-step explanation:
The program will use two variable hour and min of integer type to store the hour and min entered by user.
In case the minutes entered plus 15 is greater than or equal to 60, then hour will be incremented by 1 and respective minutes will be calculated using the following logic:
if(min+15>=60)
{
hour = ++hour;
min = (min+15)-60;
}
else
min = min +15;
Finally the hour and min value is displayed to user.