I want to create a function that prompts the user for time, written as HH:MM, where HH is stores in hour_arrived
and MM in minute_arrived
. However functions cannot return two values, is there a way I can do this?
It has to be a function since this is what is instructed in the assignment, and no built in functions are allowed. And keep in mind I want to use an if function on the time(hours and minutes variables) outside the function.
This was my attempt:
int departTime(int&hour_start, int&min_start){
string timeD;
cout<<"Departure Time on the first day of the trip in HH:MM Format: ";
cin>>hour_start;
cin.ignore();
cin>>min_start;
cin.ignore();
while((hour_start<0)||(min_start<0)|| ((hour_start>23)||(min_start>59))){
//START TIME VALIDATION CHECK
cout<<"Error, invalid time. Please try again."<<endl;
cout<<"Departure Time on the first day of the trip in HH:MM Format: ";
cin>>hour_start;
cin.ignore();
cin>>min_start;
cin.ignore();
}
timeD = hour_start + ":" + min_start;
cout<<"Dep time is: "<<timeD;
}