Ask Question
14 January, 15:24

Write a program that accepts a time as an hour and minute. Add 15 minutes to the time, and output the result. Example 1: Enter the hour: 8 Enter the minute: 15 It displays: Hours: 8 Minutes: 30 Example 2: Enter the hour: 9 Enter the minute: 46 It displays: Hours: 10 Minutes: 1, edhesive

+4
Answers (2)
  1. 14 January, 17:26
    0
    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).
  2. 14 January, 17:30
    0
    Program to accept time as hour and minute:

    #include

    using namespace std;

    int main ()

    {

    //declare variable to store hour and minutes.

    int hour, min;

    //enter hour and minutes.

    cout<<"Enter Hour:"<
    cin>>hour;

    cout<<"Enter minutes:"<
    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:"<
    }

    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that accepts a time as an hour and minute. Add 15 minutes to the time, and output the result. Example 1: Enter the hour: 8 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers