HELP PLEASE Switch Statement for Day Number

Hi everyone,

I need to do this assignment and am having trouble as i was absent from class. We were supposed to use the switch statement to convert a date into the day number.

Write a program that converts a date into its corresponding day number. The program asks the user to input any date within the current century as three whole numbers representing month, day, and year. It computes the day number corresponding to the date entered and displays it. For example, for a month value of 3, day value of 1, and year value of 2007, it displays 60.

I also need to include the boolean code. This is what i have so far and am stuck. Can someone help me?

Thanks!


#include <iostream>

using namespace std;

int main()
{
string in;
int day,month,year,dayNum;
bool leapyear;
cout << "Enter Month: ";
cin >> month;
cout << "Enter Day: ";
cin >> day;
cout << "Enter Year: ";
cin >> year;


if ((year%4)==0|&&month>2);
dayNum=dayNum+1;
switch (month)
{
case 1:
dayNum=day;
break;
case 2:
dayNum=31+day;
break;
case 3:
dayNum=59+day;
break;
case 4:
dayNum=90+day;
break;
case 5:
dayNum=120+day;
break;
case 6:
dayNum=151+day;
break;
case 7:
dayNum=181+day;
break;
case 8:
dayNum=212+day;
break;
case 9:
dayNum=243+day;
break;
case 10:
dayNum=273+day;
break;
case 11:
dayNum=304+day;
break;
case 12:
dayNum=334+day;
break;
}
cout<<endl;
cout<<"Date: "<<month<<"/"<<day<<"/"<<year<<endl;
cout<<"Day Number: "<<dayNum<<endl;
}

it says on line 18 month is not defined? help please!
Last edited on
If you could really put your code into code-tags that would be wonderful; it is the first button in the format section while you are posting, it looks like <>.

your if statement is very strange, you have a boolean or/pipe in there before a logical and. are you trying to see if it equals 0 and month is greater than 2? Also with the semicolon being right after the if the if actually does nothing, even if the statement it is checking returns true. :o
Last edited on
Topic archived. No new replies allowed.