Respuesta :
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
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.
Answer:
The solution code is written in Python:
- hour = int (input("Enter the hour: "))
- minute = int(input("Enter the minute: "))
- if(minute + 15 > 59):
- minute = (minute + 15) % 60
- hour += 1
- else:
- minute = minute + 15
- print("Hours: " + str(hour))
- print("Minutes: " + str(minute))
Explanation:
Firstly, we can use Python input() function to prompt user for input hour and minute (Line 1 - 2).
Next, create an if condition to check if the minute + 15 bigger than 59 (Line 4), calculate the total minutes modulus with 60 to get the remainder (Line 5) and add 1 to hour (Line 6).
Else, just simple add 15 to minute.
Display hour and minutes using print() function (Line 10 -11).