NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

//Making structure
struct Date
{
int month, day, year;
};

//Array for days in month
const int monthDays[12] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };

// This function counts number of leap years before the
// given date
int countLeapYears(Date day)
{
int years = day.year;

// Check if the current year needs to be considered
// for the count of leap years or not
if (day.month <= 2)
years--;

// An year is a leap year if it is a multiple of 4,
// multiple of 400 and not a multiple of 100.
return years / 4 - years / 100 + years / 400;
}

int main()
{
SYSTEMTIME ct;
GetLocalTime(&ct);
Date birth, current;
string name;
char response;
current.month = ct.wMonth;
current.day = ct.wDay;
current.year = ct.wYear;

cout << "This is my program 'Alive'. It will calculate the amount of days you have been alive.nTo start this program, please enter your name. ";
getline(cin, name);
cout << "nHello " << name << ", please enter the number of the month that you were born in: ";
cin >> birth.month;
cout << "nNow please enter the day of the month that you were born: ";
cin >> birth.day;
cout << "nFinally, please enter the year that you were born: ";
cin >> birth.year;

cout << "nYou were born on " << birth.month << "/" << birth.day << "/" << birth.year << ". Is that correct? Y/N ";
cin >> response;
if (response == 'Y' || response == 'y') {
cout << "nThe current date is " << current.month << "/" << current.day << "/" << current.year;

// This function returns number of days between two given
// dates
int getDifference(Date dt1, Date dt2);
{
// COUNT TOTAL NUMBER OF DAYS BEFORE FIRST DATE 'dt1'

// initialize count using years and day
long int n1 = dt1.year * 365 + dt1.day;

// Add days for months in given date
for (int i = 0; i<dt1.month - 1; i++)
n1 += monthDays[i];

// Since every leap year is of 366 days,
// Add a day for every leap year
n1 += countLeapYears(dt1);

// SIMILARLY, COUNT TOTAL NUMBER OF DAYS BEFORE 'dt2'

long int n2 = dt2.year * 365 + dt2.day;
for (int i = 0; i<dt2.month - 1; i++)
n2 += monthDays[i];
n2 += countLeapYears(dt2);

// return difference between two counts
return (n2 - n1);
}
cout << "Difference between two dates is " << getDifference(dt1, dt2);

return 0;
}

}
else if (response == 'N' || response == 'n') {
cout << "Please relaunch the program and try again.n";
}
return 0;
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.