Ask Question
16 August, 07:21

2.3 Code Practice: Question 3

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

+4
Answers (1)
  1. 16 August, 10:34
    0
    Code in C++

    Explanation:

    C+ + Code

    #include / /for input and output

    using namespace std;

    int main ()

    {

    int hour;

    int minute;

    cout<<"Enter the hour:";

    cin>> hour;

    cout<<"Enter the minute:";

    cin>>minute;

    minute = minute+15;

    if (minute>=60) {

    hour++;

    minute=minute-60;

    }

    if (hour>=24) {

    hour=0;

    }

    cout<<"Hours: "<
    cout<<"Minutes:"<
    return 0;

    }

    Code Explanation

    First we need to declare two int variables to hold hour and minute values input from user.

    Check if by adding 15 minutes into minute entered by user is greater then or equal to 60 then increment into hour and subtract 60 from minute.

    Another check is that if user enters more then 24 hour or by making increment into hour, the hour values i greater then or equal to 24 then we need to change the hour to 0.

    Result

    Case 1:

    Enter the hour:8

    Enter the minute:15

    Hours: 8

    Minutes:30

    Case 2:

    Enter the hour:9

    Enter the minute:46

    Hours: 10

    Minutes:1
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “2.3 Code Practice: Question 3 Write a program that accepts a time as an hour and minute. Add 15 minutes to the time, and output the result. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers