SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Functions For All Subtasks
Exercise:
Programming Projects
Question:2 | ISBN:9780321531346 | Edition: 7

Question

Write a program that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24 hour notation for the times. Include a loop that lets the user repeat thiscalculation for additional input values until the user says she or he wants to end the program.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

#include<iostream>
using namespace std;
void main()
{  

	int currHours,currMins,hoursWait,minutesWait;
	int hrs,min;
	char choice;
	do
	{

        		cout<<"Enter present Hours:";
	  	cin>>currHours;
	  	cout<<"Enter present minutes:";
	  	cin>>currMins;	
 	  	cout<<"Enterthe number of hours to wait:";
	  	cin>>hoursWait;
	  	cout<<"Enter the number of minutes to wait:";
	 	 cin>>minutesWait;
        		 hrs=currHours+hoursWait;
	 	 min=currMins+minutesWait;
	 	 if(min>=60)
	 	 {
		  hrs++;
		  min =min-60;
	 	 }
	  cout<<"Time:"<<hrs<<":"<<min<<endl;
	  cout<<"Do you want to continue then press y or Y:";
	  cin>>choice;
     }while(choice == 'Y' || choice =='y');
}

Output:

Enter present Hours:10
Enter present minutes:20
Enterthe number of hours to wait:2
Enter the number of minutes to wait:10
Time:12:30
Do you want to continue then press y or Y:n

 

0 0

Discussions

Post the discussion to improve the above solution.