A user wishes to enter a starting time AM/PM format, and delay time in hours and minutes, and have the computer compute and display the time (in AM/PM format) at the end of the delay.
This process should repeat until the user enters 999 for the hours portion of the start time.
Note: The user will enter the start time as two integers and either 'A' 'a' 'P' 'p' with a space (or spaces in-between them, the first representation the hours portion of the time , and second representation the minutes portion of the time and the characters representing either AM or PM. The delay timed will be entered in a similar way.
Example: if the user enters the time 10 13 A
and a delay time of 2 05
then the computer should display 12:18pm as the time at the end of the delay.
The program is by no means finished but I have no clue where to go from where I am at in the program. It could all be wrong for what I know. Any help would be appreciated
//Programming project #2
#include <iostream>
void computeTimeDifference(int& H, int& M, int& H1, int& M2, int AP )
int main()
{
int H;
int M;
int H1;
int M2;
int AP;
cout << "Enter start time." << endl;
cout << "Enter hours and minutes aswell as either A for AM or P for PM: ";
cin >> H >> M >> AP >> endl;
cout << "Enter delay time." << endl;
cout << "Enter hours and minutes: ";
cin >> H1 >> M2 >> endl;
computeTimeDifference(int& H, int& M, int& H1, int& M2, int AP);
cout << endl << "Delay Time: " << << ":" << endl;
return 0;
}
void computeTimeDifference(int& H, int& M, int& H1, int& M2, int AP)
{
Okay I understand most of that program except for the functions at the beginning and the const int in the middle of the program. I appreciate your help greatly ,but I just want to understand what these things mean In the program.
// given an input of the time of day in hours and minutes
// returns the number of minutes elapsed since midnight
// for instance, if the input is 10 hours, 30 minutes
// return 630 ( 10*60 + 30 )
// if the input is out of range, say 27 hours, 72 minutes,
// it is adjusted appropriately: 27:72 == 28:12 == 04:12 on the next day
// we do this by dividing the result by the total number of minutes
// in a day (24*60) and taking the remainder
int minutes_since_midnight( int hh, int mm )
{ return ( hh*60 + mm ) % (24*60); }
// given an input of the number of minutes elapsed since midnight
// return the hour part of the (24-hr) time of day. we do this by dividing
// the total number of minutes by the number of minutes in an hour (60)
// as in the first function, if the input is out of range it is adjusted
int hour( int minutes_since_midnight )
{ return minutes_since_midnight % (24*60) / 60 ; }
// given an input of the number of minutes elapsed since midnight
// return the hour part of the (24-hr) time of day. we do this by dividing
// the total number of minutes by the number of minutes in an hour (60)
// and taking the remainder of the division
int minute( int minutes_since_midnight )
{ return minutes_since_midnight % 60 ; }
A const int is an immutable int; once it has been initialised, its value can never be changed.
If we accidentally try to modify it, because of a programming error, the compiler will point out the error.
See: http://www.cplusplus.com/forum/beginner/180986/#msg888218
My proffesor doesnt want use to be using anything but the #include<iostream.h> and he only want one function in the program. He gave me some Psuedocode that he wants the program to roughly look like. How would you translate the program you made to this?
//Only one function can be used
//<iomanip> cannot be used in the program
Int main()
{
Int startHours;
Int startMins;
//ect.
getValues ( StartHours,StartMins, ect)
while(startHours !=999)// The Program is supposed to end when the user inputs 999 for the hours value.
{
getValues()
}//end main()
void getValues (int& startHours, int& startMins, ect)
{
cout<<
cin>>startHours;
}