Trouble with Bool Function return

I'm currently coding a time clocking program for my university intro CS class that is supposed to check input times and calculate pay, length of time, overtime etc.

currently my code looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

const double MINTUES_IN_HOUR = 60;
const double OVERTIME_PAY = 1.5 * 8;
const string TIME_ERROR = "Invalid time. Please use (hh:mm A/P) format.";


bool validate_times ( int time1, int time2, char ap );

int main()
{
	double payrate;
	int start_hour, start_minute, end_hour, end_minute;
	string name;
	char colon, start_ap, end_ap;

	cout << "Time Clock Program" << endl << endl
		<< "Enter worker name:  ";
	getline(cin, name);
	cout << "Enter start time (hh:mm A/P):  ";
	cin >> start_hour >> colon >> start_minute >> start_ap;
	validate_times (start_hour , start_minute , start_ap);
	cout << "Enter stop time (hh:mm A/P):  ";
	cin >> end_hour >> colon >> end_minute >> end_ap;
	validate_times (end_hour , end_minute , end_ap);
	
	cout << "Enter pay rate:  ";
	cin >> payrate;

system("pause");
return 0;
}

bool validate_times ( int time1, int time2, char ap )
{
	if ( time1 > 12 )
		return cout << TIME_ERROR;
	else 
		if ( time2 > 59 )
			return cout << TIME_ERROR;
		else 
			if ( ap != 'a' || ap != 'p' ) 
				return cout << TIME_ERROR;
			
}



Forgive the messiness as it is nowhere near complete of course.

The problem I am having is my "validate_times" function that is supposed to check and see if the input time matches the correct format requested. I was able to get everything to work up until
1
2
3
if ( ap != 'a' || ap != 'p' ) 
				return cout << TIME_ERROR;
			
.
I need the function to check and make sure that the character for the "am" and "pm" are either "A","a","P", or "p". The code will work fine if I take out the OR operator in the last part of the function, but how else would I get it to be able to allow "p" as well as "A" and "P"?

Sorry if this seems confusing my English is not very good.

Thank you for your time.
You have a choice

if ( ap != 'a' && ap != 'A' && ap != 'p' && ap != 'P' )

which is the same as:
if ( ! (ap == 'a' || ap == 'A' || ap == 'p' || ap == 'P') )
Thank you so much. You are a live saver.
Topic archived. No new replies allowed.