Help with Array Assignment
Hello, I am a beginner programmer
I am looking for some help with this assignment
Assignment - Develop a C++ program that can be used to calculate the number of days between any two days from 1/1/1900 through 12/31/2099
The main program will call the same function twice - once for each date and have an integer returned to it each time
The normal year array should contain:
{ 0, 0, 31, 60, 91, 121, 152, 182, 213, 243, 273, 304, 334, 365};
The program will use additional arrays for leap year, day of month, and other requirements
Any type of help is much appreciated!
[622 byte] By [
youngone] at [2007-11-11 10:28:31]

# 2 Re: Help with Array Assignment
what i have so far
#include <iostream>
#include <math.h>
#include <stdlib.h>
int main(void)
{
int month = 0;
int month2 = 0
int day = 0;
int day2 = 0;
int year = 0;
int year2 = 0;
numofdays = 0;
julianDate = 0;
const int DaysInMonth[13] = {0,31,28,31,30,31,30,31,31.30,31,30,31};
const int DaysInYear[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334,365};
const int DaysInLeapYear[13] = {0,0,31,60,91,121,152,182,213,244,274,305,335,366};
cout << "\n Calculates # of days between dates" << endl;
cout << "\n give a date (ex: 2 28 2007):"<< endl;
cin >> month >> day >> year;
if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year < 2099 )
{
cout << "One of the numbers you entered is incorrect\n";
cout << "try entering it again (ex: 2 28 2007): ";
cin >> month >> day >> year;
}
cout << "\n give another date" << endl;
cin >> month2 >> day2 >> year2 << endl;
if (month2 < 0 || month2 > 12 || day2 < 0 || day2 >31 || year2 > 1900 ||| year2 < 2099 )
{
cout << "One of the numbers you entered is incorrect\n";
cout << "Try entering it again (ex: 2 28 2007): ";
cin >> month2 >> day2 >> year2;
}
juliandate =
cout << month << day << year << endl;
cout << month2 << day2 << year2 << endl;
cout << "# of days between these dates is: " << numofdays;
}
The thing i'm really confused about is how to use arrays - how to add up the days using them?
Also the julian date is confusing, i researched and found a bunch of different formulas on julian date i don't know which one i would use in this case?
any helpis appreciated
# 3 Re: Help with Array Assignment
it sounds like you need to determine the elapsed days from 01/01/1900 to your start date, then 01/01/1900 to your finish date, then subtract those two numbers.
The trick to this will be determining which of the two "days in year" array to use. What are the rules for determining what a leap year is?
so you will be using
years = year in question - 1900
leapYears = years/4 [ +1? is 1900 a leap year?] ;
standardYears = years - leapYears.
use leapYears*daysInLeapYear[12] + standardYears * daysInYear[12] to determine the number of days in the elapsed whole years.
the month + day result is a "how many days in this partial year" result.
So, determine if the date in question is in a leap year, go to the index in the appropriate cumulative days in the year array for the month, and it will give you the total days that year before the first day of the current month. Add that value plus the "day of the month" value and you get the number of elapsed days in the current year.
nspils at 2007-11-11 21:00:44 >
