86.2k views
0 votes
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

1 Answer

3 votes

Answer:

Step-by-step explanation:

C++ Code

#include <iostream>

#include <cstdlib>

using namespace std;

int main(){

double hour,minute;

cout<<"Enter Hours :";

cin>>hour;

cout<<"Enter Minutes :";

cin>>minute;

minute = minute+15;

if(minute >=60){

hour++;

minute = minute-60;

}

if(hour>23){

hour = 0;

}

cout<<"Hour: "<< hour<< " Minutes: "<<minute;

return 0;

}

Code Explanation

First take hours and minutes as input. Then add 15 into minutes.

If minutes exceeds from 60 then increment into hours and also remove 60 from minutes as hours already incremented.

Then check if hours are greater then 23 then it means new day is start and it should be 0.

Output

Enter Hours :9

Enter Minutes :46

Hour: 10 Minutes: 1

User Alessio Firenze
by
4.8k points