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
#include <iostream>
usingnamespace 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