Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- struct Date {
- int year{};
- int month{};
- int day{};
- };
- int days_number(int year, int month, int day) {
- int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (year % 4 == 0) {
- days_in_month[1] = 29;
- }
- int total_days = 0;
- for (int i = 0; i < month - 1; ++i) {
- total_days += days_in_month[i];
- }
- total_days += day;
- return total_days;
- }
- int main() {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- Date date{};
- while (true) {
- cout << "Введіть рік: ";
- cin >> date.year;
- if (cin.fail()) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Рік було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть номер місяця (1-12): ";
- cin >> date.month;
- if (cin.fail() || date.month < 1 || date.month > 12) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Номер місяця було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть номер дня (1-31): ";
- cin >> date.day;
- if (cin.fail() || date.day < 1 || date.day > 31) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Номер дня було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- int result = days_number(date.year, date.month, date.day);
- cout << "Кількість днів від початку року до цієї дати: " << result << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement