-
Can u fix this?
// Rob Gross
// Midterm
// 3/11/02
// Due Thursday
#include <iostream>
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 fdate;
int smonth;
int sdate;
cout << "Enter your first Month and Date: " << endl;
cin >> fmonth >> fdate;
cout << "Enter your second Month and Date: " << endl;
cin >> smonth >> sdate;
difference = (days [fmonth - 1] - fdate);
cout << difference << " days between the dates. " << endl;
return 0;
}
My computer crashes on this line
difference = (days [fmonth - 1] - fdate);
what is wrong is that I have it set to nothing.
The point of this project is to calculate the number of days that the user enters when they enter a month and a date twice.
You understand?
-
Although I don't understand what this line shall accomplish, the pogra works for me. You might be giving it wrong input. Valid would be for example:
3 12
7 25
Then fmonth would be 3, fdate 12, smonth 7 and sdate 25.
-
If you want the day difference between two dates, here is a working program (yours a little bit modified)
Code:
int main ()
{
int days [12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int difference;
int fmonth;
int fdate;
int fdays = 0;
int smonth;
int sdate;
int sdays = 0;
int i;
cout << "Enter your first Month and Date: " << endl;
cin >> fmonth >> fdate;
cout << "Enter your second Month and Date: " << endl;
cin >> smonth >> sdate;
for(i = 0; i < fmonth-1; i++)
fdays += days[i];
fdays += fdate;
for(i = 0; i < smonth-1; i++)
sdays += days[i];
sdays += sdate;
difference = (sdays - fdays);
cout << difference << " days between the dates. " << endl;
return 0;
}
Note: for more readability, always wrap your code in [ code]-[/ code] or [php ]-[/php ] tags (without the spaces)