Boolean Function Help?!

Hello, thank you for the help in advance.

My problem is that I have my bool function testing to see if the times entered are valid, if they are it returns true back to main, if false it returns to "void getTime" where a do-while loop will restart the function.

But i'm not sure what value is supposed to go at the end of the while loop (i have "validInput" there now), but its only showing up as "invalid entry" whenever i run it, even if the numbers are lower than the const ints.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// HEADER
// TIME.H

#include <iostream>
using namespace std;

const int MAX_HOURS = 23;
const int MAX_MINS = 59;
const int MAX_SECS = 59;

struct Time 
{
	int hours;
	int minutes;
	int seconds;
};
//=============================================
// MAIN
// MAIN.CPP

#include "Time.h"

void getTime(Time & time);
bool isTimeValid(Time & time);

int main()
{
	Time time;

	getTime(time);

	return 0;
}
//--------------------------------------------------
void getTime(Time & time)
{
	bool validInput = isTimeValid(time);

	do{
	cout << "Enter the time in \"military time\", (24-hour format), "
		 << "\n\tin the following order: HH:MM:SS, (Hours, Minutes, Seconds).\n";
	cout << "\nHours: ";
	cin >> time.hours;
	cout << "\nMinutes: ";
	cin >> time.minutes;
	cout << "\nSeconds: ";
	cin >> time.seconds;

	isTimeValid(time);
	
	cout << "\nInvalid time!\n\n";

	}while (validInput != true);
}
//--------------------------------------------------
bool isTimeValid(Time & time)
{
	if ((((time.hours >=0) && (time.hours <= MAX_HOURS)) && 
		 ((time.minutes >=0) && (time.minutes <= MAX_MINS))) && 
		 ((time.seconds >=0) && (time.seconds <= MAX_SECS)))
		return true;
	else
		return false; 
}
//--------------------------------------------------

Line 37 should only be bool validInput since time as no value yet

Line 49 should be wher you assign the value validInput = isTimeValid(time)
Works great, thank you.
Topic archived. No new replies allowed.