|
-
Apr 2nd, 2002, 11:09 PM
#1
Thread Starter
Addicted Member
dates
listed below is my program. HEre is what i need to do:
1. Write a program to calculate the number of days between two dates. Each date is represented by three integers: day, month, and year. Minimum requirements: you are not required to determine leap years; this is, you may consider that February always has 28 days. A leap year is one whose number is exactly divisible by four. Century years, however, are only leap years if they are exactly divisible by 400. Hence 1900 was not a leap year but 2000 was.
I need help with year as well.
But what is wrong with my program.
Please help!
here is my program:
//Rob Gross
//Recursive
//3/13/02
#include<iostream.h>
int largest (int *num, int n)
{
int larg=*num;
if (n>1)
{
cout << "Entering function with n=" << n << " and element of the array=" << *num << endl;
larg=largest(&num[1], --n);
cout << "The largest element within the " << n << " last elements is " << larg << endl;
if (*num>larg)
larg=*num;
num++;
}
return larg;
}
void main()
{
int num[10]={23,19,5,2,8,13,3,20,15,18};
int n=10;
cout << endl << "The largest element of " << n << " elements is " << largest(num, 10) << endl ;
}
ICQ = 20476917
AIM = Butnud
Lets Talk!
-
Apr 3rd, 2002, 07:04 AM
#2
Whatever you're doing, this might help you.
Code:
inline bool IsLeap(year)
{
return (year % 4 == 0) ^ (year % 400 == 0) ^ (year % 100 == 0);
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 3rd, 2002, 08:59 AM
#3
Thread Starter
Addicted Member
I must have been on drugs or soemthing.
The above code is a recurcive program not the one I wanted you top help me with.
grrrr
Below is the correct coding!
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int days [12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int difference;
int fmonth;
int fday;
//int fyear;
int smonth;
int sday;
//int syear;
//string Date1, Date2;
cout << "Enter the first date:\t";
cin >> fmonth >> fday;
cout << "Enter the second date:\t";
cin >> smonth >> sday;
if(fmonth != smonth)
{
difference = (days[fmonth - 1] - fday);
for(int Counter = fmonth + 1; Counter < smonth; Counter++)
difference += days[Counter - 1];
difference += sday;
}
else
difference = sday - fday;
cout << difference << " days between the dates. " << endl;
return 0;
}
Please tell me where I should put the code and what code?
If you say well you should try this, that won't help me!
Thank you!
ICQ = 20476917
AIM = Butnud
Lets Talk!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|