Hello,
I'm a little lost as to how to get the day part of my function to come up properly without a garbage number as it wants to do at the moment. I have everything else working well until it doesn't return the day on line .
#include<iostream>
#include<cmath>
void getTime(int& cHours,int& cMinutes,int& hWait, int& mWait, char colon);
void timeCalc(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM);
void printTime(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM, int& nDays);
char getResponse();
int main()
{
int cHours,cMinutes,hWait,mWait,waitH,waitM,nMin,nDays;
char rerun,colon;
do
{
getTime(cHours,cMinutes,hWait,mWait,colon);
timeCalc(cHours,cMinutes,hWait,mWait,waitH,waitM);
printTime(cHours,cMinutes,hWait,mWait,waitH,waitM,nDays);
rerun = getResponse();
}while(rerun == 'y');
return 0;
}
void getTime(int& cHours,int& cMinutes,int& hWait, int& mWait, char colon)
{
using namespace std;
cout << "\nPlease enter the current time in 24 hour notation HH:MM." << endl;
cin >> cHours >> colon >> cMinutes;
cout << "\nPlease enter the amount of time to wait. Example HH:MM." << endl;
cin >> hWait >> colon >> mWait;
//cout << "\nThe time is: " << cHours << colon << cMinutes << endl;
//cout << "\nThe wait is: " << hWait << colon << mWait <<endl;
}
void timeCalc(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM)
{
using namespace std;
int nHours,nDays;
waitH = cHours + hWait;
waitM = cMinutes + mWait;
if ( waitM > 59 )
{
nHours = waitM /60;
waitM = waitM % 60;
waitH = waitH + nHours;
cout << waitH << " hours" <<endl;
//cout << nHours << "hours2";
//cout << waitM << "minutes";
nDays = waitH / 24;
//waitH = waitH % 24;
//nDays = waitH + days;
//cout << days << "\n days";
//cout << waitH << " hours";
cout << nDays << " new days" << endl;;
return;
}
else( waitM <=59);
{
printTime(cHours,cMinutes,hWait,mWait,waitH,waitM,nDays);
}
}
void printTime(int& cHours,int& cMinutes,int& hWait, int& mWait, int& waitH,int& waitM, int& nDays)
{
using namespace std;
cout << "\nThe time after the waiting period will be." <<endl;
if( nDays >= 1)
{
cout << nDays << " day(s) and" << waitH << ":" << waitM << " and minute(s)";
}
else( nDays < 1);
{
cout << waitH << ":" << waitM;
}
cout << endl;
}
char getResponse()//This is the function that will ask for input from the user so the program will either rerun of terminate..
{
using namespace std;//Used per function no longer used globally.
int cHours,cMinutes,hWait,mWait,waitH,waitM;
char response,rerun,colon;//Local variables to this function.
do//Beginning of the do-while loop.
{
cout << "\nDo you want to continue? (y for yes, n for no): ";//Prompt asking if continuation is wanted.
cin >> response;
if (response != 'y' && response != 'n' )//The if-loop to make sure the user inputs a y or n to get appropriate input.
{
cout << "\nInvalid input, enter y or n" << endl;//Output asking user to make sure to use correct input.
}
else if (response == 'y')
{
getTime(cHours,cMinutes,hWait,mWait,colon);
timeCalc(cHours,cMinutes,hWait,mWait,waitH,waitM);
rerun = getResponse();
}
else
{
cout << "\nGoodbye!";//If user chooses n then program terminates.
cout << endl;
}
}while(response != 'y' && response != 'n');
response = rerun;
}