nested ifs

Hi all and thanks for any help.

I'm Finishing up my finals and my brain is fried. Why oh why is this nested if not setting the value (hour += 12 ) properly?

1
2
3
4
5
6
7
8
9
10
11
12
13
  cout << "hours:";
    cin >> hour;

	if (hour > 12)
	  {
		 hour += 12;
		 if (hour > 17)
		 {
	           cout << "Office hours do not end later than 5:00pm \n";
		   cout << "Please enter your starting time: \n";
		   cout << '\n';
		 }
	}
Last edited on
what are you trying to accomplish? I'm confused by your code also.

if you are just trying to print out the message if somebody enters a value greater than 17 then i don't think you would need to nest the second if statement.
Last edited on
I'm trying to code,

"if hour is greater than 12, then add 12 to hour, then if hour is over 17, validate loop"

I know, like I said my brain is sputtering lol
That makes sense in english but not for a computer.

The person should have already input the hour with +12 in it by the time it reaches your if statement.

You don't need to add 12 unless you are going to add a feature that would let you check if it was AM or PM. Then you wouldn't ask the person to add 12 to begin with.
Last edited on
Thanks, I changed the code already. Had a moment of clarity.
Topic archived. No new replies allowed.