I'm trying to test for valid hours and minutes, and exit void getInput(int hours, int minutes) cleanly without going on to the next step as if they were valid. Sorry if this is not clear, what I am going round and round with is when I have an invalid input ,I want to continue the loop and ask for another time, without printing the output as if it were valid. What I have tried either exits without asking if user wants to exit(required) or reports the input is invalid and then couts the time as if it were valid. I am really confused. I think my problem may be with the way I am doing the bool test in this line: if ((!validhours) || (!validmins))
Any help is appreciated
#include <iostream>
using namespace std;
//function definitions
void getInput(int hours, int minutes);
int main()
{
char cont = 'y';
int hours, minutes, hours12;
cout<< "Timer\n";
//call functions
getInput(hours, minutes);
do
{
cout << "Would you like to enter another time? \n";
cin >> cont;
}
while (cont== 'y'|| cont =='Y');
cout << "Thank you.\n";
return 0;
}
// get input
void getInput(int hours, int minutes){
int hours12, mins;
char niteday;
cout << "Please enter hours: ";
cin >> hours12;
cout << "Enter 'A' for am or 'P' for pm ";
cin >> niteday;
cout << "Please enter minutes: ";
cin >> mins;
bool validhours = (hours12 < 1 || hours12 >12);
if (validhours){
cout << hours12 << " is not a valid hour." << endl;
//return 0;
}
bool validmins = (mins < 1 || mins > 60);
if (validmins){
cout << minutes << " are not valid minutes." << endl;
//return 0;
if ((!validhours) || (!validmins))
cout << "Current time is " << hours12 << ":" << minutes << endl;
}
}