Question: #include using namespace std; int main() { int year, leap, nonleap; // declares year, leap, and nonleap as integers leap = 366*24*3600; // calculates the

#include

using namespace std;

int main()

{

int year, leap, nonleap; // declares year, leap, and nonleap as integers

leap = 366*24*3600; // calculates the seconds in a leap year

nonleap = 365*24*3600; // calculates the seconds in a nonleap year

cout<<"(Note a year of -99 will close the program) " << endl; // prompts the user an integer value of -99 will end the program

for( ; ; ) // loops the program indefinitely until the integer value -99 is enetered

{

cout<<"Enter the year: "; // prompts the user to enter a year

cin>>year; // accepts the value for integer year

if (year==-99) // checks if -99 is entered

exit(0); // ends the program

else if( (year%400==0 || year%100!=0) &&(year%4==0)) // determines wether or not it is a leap year

cout<<" It is a leap year. Seconds in this year: " << leap << " " << endl; // outputs that it is a leap year and how many seconds are in the leap year

else

cout<<" It is not a leap year. Seconds in this year: " << nonleap << " " << endl; // outputs that it isnt a leap year and how many seconds are in the year

}

return 0; // returns end value zero

}

First, turn the code into a user-defined function. The function takes a year number as input and returns an integer. There are three return possibilities: return value -1 means that an incorrect number was passed in (year < 1). Return value 0 means the input year is not a leap year. Return value 1 means the year is a leap year.

This functions code is put in after main(), but a prototype is defined before main().

Call the function from a sentinel-controlled loop which prompts the user for a year, and tells the user that the input is (a) a leap year; (b) not a leap year; (c) not a valid year.

The seconds and the -99 kill switch shall be removed and will no longer have to be looped endlessly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!