Help please

I don't know what I'm doing wrong, please help.




Write a program that prints the day number of the year, given the date in the form month-day-year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  #include <iostream>
using namespace std;
bool isLeapYear(int year);
bool isLeapYear(int year)
{   
    if ((year  % 4 == 0) && (year % 100 != 0))
        ((year % 100 == 0) &&(year % 400 == 0));
    {
        cout << year << " is a leap year";
        return true;
}
    return false;
}
    int main ()
    {
        int day, month, year, dayNumber;
        char ch;
        cout << "\n\n\tEnter a date(mm-dd-yyyy) : ";
        cin >> month;
        cin >> ch;
        cin >> day;
        cin >> ch;
        cin >> year;
        dayNumber = 0;
        
        if ((month >= 1 && month <= 12) && (day >=1 && day <= 31))
        {
            while (month > 1 && month <= 12)
                {
                        switch (month - 1)
                        {
                            case 1:
                            case 3:
                            case 5:
                            case 7:
                            case 8:
                            case 10:
                            case 12:
                                dayNumber += 31;
                                break;
                            case 4:
                            case 6:
                            case 9:
                            case 11:
                                dayNumber += 30;
                                break;
                            case 2:
                                dayNumber += 28;
                                if (isLeapYear(year))
                                    dayNumber++;
                                break;
                        }
       month--;
         }
            }
            else {
                cout << "Enter Correct month or day";
                return 0;
            }
            dayNumber += day;
            cout << "\n\n\tThe day number is " << dayNumber;
            return 0;
        }
Don't put semi-colons after if-statements.
Make sure every logical check in an if statement is separated by an operator (e.g. ||, &&) [look at lines 6-7]

Indent your code properly, this looks really bad:
1
2
3
4
5
                        }
       month--;
         }
            }
            else {
Last edited on
Topic archived. No new replies allowed.