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
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
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...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
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...