The user enters his date of birth and the current date. Count the number of days lived. Where is the mistake?

#include<iostream> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int day1, month1, year1, sum1 = 0, sum2 = 0, count = 0; int day2, month2, year2; int mon[12] = {31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; cout << "Введите дату рождения: "; cin >> day1 >> "." >> month1 >> "." >> year1; cout << "Введите дату сегоднешнего дня: "; cin >> day2 >> "." >> month2 >> "." >> year2; //////////////////////ПЕРВАЯ ЧАСТЬ for (int i = 0; i < (year1 - 1); i++) { if (i % 4 != 0) { sum1 += 365; } else { sum1 += 366; } } for (int j = 0; j < (month1 - 1); j++) { sum1 += mon[j]; } if (year1 % 4 != 0) { sum1 += day1; } else if ((year1 % 4 == 0) && (month1 > 2)) { sum1 += (day1 + 1); } else { sum1 += day1; } ////////////////////ВТОРАЯ ЧАСТЬ for (int i = 0; i < (year2 - 1); i++) { if (i % 4 != 0) { sum2 += 365; } else { sum2 += 366; } } for (int j = 0; j < (month2 - 1); j++) { sum2 += mon[j]; } if (year2 % 4 != 0) { sum2 += day2; } else if ((year2 % 4 == 0) && (month2 > 2)) { sum2 += (day2 + 1); } else { sum2 += day2; } ///////////////////ВЫВОД cout << "Количество прожитых дней: " << sum2 - sum1 << endl; return 0; } 
  • And what is the actual error? - iluxa1810
  • It simply does not start - Asya Filatova
  • And what a mistake? - iluxa1810
  • "" C: \ Users \ user \ Desktop \ Projects \ Laba3 \ Debug \ A7.exe "" is not an internal or external command, executable program or batch file. - Asya Filatov
  • Much easier, using the mktime function (or you can read man 3 mktime ) get the dates in seconds . Then just divide the difference in seconds by the length of the day in them ( 24 * 60 * 60 ) - avp

2 answers 2

It is simply NOT COMPILED with you, there is nothing to be launched!

How do you imagine this passage:

 cin >> day1 >> "." >> month1 >> "." >> year1; 

What does it mean to enter into the literal "." ?

No program - nothing to run ...

Work on the text.

PS I recommend, by the way, to look in the direction of the modified Julian date - the program will be greatly simplified immediately ...

PPS By the way, it will not play within the limits of the XX and XXI centuries, but keep in mind that not all years that are divided into 4 are leap years ...

  • Ok, and then how to display the date through the points? - Asya Filatov
  • one
    Print or enter? cin>> is data entry ... For example, output like this: cout << day << "." << month << "." << year; cout << day << "." << month << "." << year; . Of course, it is better to output with leading zeros for single digits, but first, just start the program ... - Harry

Probably because February 28/29 days, and in the given code - thirty.

UPD :

 int mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; cout << "Введите дату рождения: "; cin >> day1; cin >> month1; cin >> year1; cout << "Введите дату сегоднешнего дня: "; cin >> day2; cin >> month2; cin >> year2; //////////////////////ПЕРВАЯ ЧАСТЬ 
  • doesn't work anyway, it doesn't even start - Asya Filatova
  • Try this (see above). The date only needs to be entered not through a point, but through a space. - Ildar Khairullin