C
C++ newbie
I am trying to write a program that returns the dayNumber for a given
date. I have wrote a program that uses nested if statements. The
problem is it only executes the first if statement and nothing else. I
will post a little of the code to see if anyone can help. All input
appreciated!!!
int month;
int day;
int year;
int dayNumber = 0;
cout<< "Enter a date: ";
cin >> month;
cin >> day;
cin >> year;
if(month > 1)
dayNumber = 31;
else if(month > 2)
dayNumber = 31 + 28;
else if(month > 3)
dayNumber = 31 + 28 + 31;
else if(month > 4)
dayNumber = 31 + 28 + 31;
else if(month > 5)
dayNumber = 31 + 28 + 31 + 30;
else if(month > 6)
dayNumber = 31 + 28 + 31 + 30 + 31;
else if(month > 7)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30;
else if(month > 8)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31;
else if(month > 9)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
else if(month > 10)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
else if(month > 11)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
else if(month > 12)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31
+ 30;
date. I have wrote a program that uses nested if statements. The
problem is it only executes the first if statement and nothing else. I
will post a little of the code to see if anyone can help. All input
appreciated!!!
int month;
int day;
int year;
int dayNumber = 0;
cout<< "Enter a date: ";
cin >> month;
cin >> day;
cin >> year;
if(month > 1)
dayNumber = 31;
else if(month > 2)
dayNumber = 31 + 28;
else if(month > 3)
dayNumber = 31 + 28 + 31;
else if(month > 4)
dayNumber = 31 + 28 + 31;
else if(month > 5)
dayNumber = 31 + 28 + 31 + 30;
else if(month > 6)
dayNumber = 31 + 28 + 31 + 30 + 31;
else if(month > 7)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30;
else if(month > 8)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31;
else if(month > 9)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
else if(month > 10)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
else if(month > 11)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
else if(month > 12)
dayNumber = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31
+ 30;