Problem with function call:

I have to write a program that ask user to enter hours in one function. I need to validate in another function outside main. When I run my program, it does not work. So, I need help to fix it.


// This is my code

#include <iostream>
using namespace std;

int getHours();
int validateHours();

void main()
{
getHours();
validateHours();
} // main

int getHours()
{
int hours = 0;
cout << "Enter the hours used: " << endl;
cin >> hours;
return hours;
}//getHours

int validHours()
{
int hours = validateHours();
// Validate the number of hours used
while (hours < 0 || hours > 720)
{
cout << "Invalid hours! Hours cannot be negative or more than 720. " << endl
<< "Enter the number of hours used: " << endl << endl;
cin >> hours;
}
return hours;
}//getHours
here it is:

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
#include <iostream>
using namespace std;

int getHours();
int validateHours(int hours);///takes arguement int

int main()///main is always int
{
int hours=getHours();///to save the return value of function
hours=validateHours(hours);
} // main

int getHours()
{
int hours;
cout << "Enter the hours used: ";
cin >> hours;
return hours;
}//getHours

int validateHours(int hours)///validHours not defined
///int hours = validateHours()
// Validate the number of hours used
{
while (hours < 0 || hours > 720)
{
cout << "Invalid hours! Hours cannot be negative or more than 720. " << endl
<< "Enter the number of hours used: ";
cin >> hours;
}

return hours;
}//getHours



P.S. =plz use "<>" to use code.
Koopey, thank you for help.
Topic archived. No new replies allowed.