Question

Use C++ only. 1) Write a full program that will take a list of years and...

Use C++ only.

1) Write a full program that will take a list of years and it will check if they are leap years. As soon as the program finds the first leap year from the list, the program terminates. The program also terminates when it reads a -1.

Please make use of the do . . . while loop structure and the break statement.

Example of sample runs:

Enter a list of years:
1841 1854 1862 1875 1879 1892 1896 1903 -1

Leap Year found: 1892

Program terminated.

(OR)

Enter a list of years:
1841 1854 1862 1875 1879 1895 1898 1903 -1

No Leap Years found!

Program terminated.

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int main() {
    int year;
    cout << "Enter a list of years:" << endl;
    do {
        cin >> year;
        if (year == 0) {
            cout << "\nNo Leap Years found!" << endl;
            break;
        }
        if ((year % 400 == 0 || year % 100 != 0) && (year % 4 == 0)) {
            cout << "\nLeap year found: " << year << endl;
            break;
        }
    } while (true);
    cout << "Program terminated." << endl;
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas,...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas, the following les for each of your programs: (1) the client and the server source les each (2) the client and the serve executable les each (3) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identiers suitable, to enable enhanced readability of the code. Problems 1. Write an ftp client that...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons for the failure and how did the breakdown harm Nike? 2. What are the important elements to be kept in mind while implementing a new system in an organization? What is the importance of a good working relationship between partners and the sharing of responsibility in implementing critical projects? What mistakes did Nike and i2 make? 3. comment on the lessons learned and the...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT