Write a method named enough time for lunch that accepts four
Solution
bool enoughTimeForLunch(int h1,int m1,int h2,int m2)
{
int t1 = h1*60 + m1; // calculating the first time in terms of minutes
int t2 = h2 * 60 + m2; // calculating the second time in terms of minutes
int time = t2 - t1; // Calculating the difference between the 2 time periods in minutes
if ( time >= 45 ) // Checking whether the minimum time difference is 45 minutes or more
return(true); // Return true as required by question
else // If difference between is less than 45 minutes
return(false); // Return false as required by question
}
For Example :
bool enoughTimeForLunch(11,00,11,59)
{
int t1 = h1*60 + m1; // t1 = 660
int t2 = h2 * 60 + m2; // t2 = 660 + 59
int time = t2 - t1; // time = 660 - (660 + 59) => time = 59
if ( time >= 45 ) // if (59 > 45)
return(true); // Return true
else // Skipped by defaut
return(false); // Skipped by defaut
}

