/* Program for displaying the day number and day name of a year (not leap) after getting month and date as input. (Without using string) Let day-1=Tuesday */ #include<iostream> #include<string> using namespace std; int main() { int month, date, day; string DayName; do { cout << "Enter Month (1-12)?\t"; cin >> month; } while (month > 12 || month < 1); if (month == 1) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = date; } else if (month == 2) { do { cout << "Enter Date (+ve number less than 28)?\t"; cin >> date; } while (date > 28 || date < 1); day = 31 + date; } else if (month == 3) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 59 + date; } else if (month == 4) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 90 + date; } else if (month == 5) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 120 + date; } else if (month == 6) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 30 || date < 1); day = 151 + date; } else if (month == 7) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 181 + date; } else if (month == 8) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 212 + date; } else if (month == 9) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 243 + date; } else if (month == 10) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 273 + date; } else if (month == 11) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 304 + date; } else if (month == 12) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 334 + date; } if (day % 7 == 0) DayName = "Monday"; else if (day % 7 == 1) DayName = "Tuesday"; else if (day % 7 == 2) DayName = "Wednesday"; else if (day % 7 == 3) DayName = "Thursday"; else if (day % 7 == 4) DayName = "Friday"; else if (day % 7 == 5) DayName = "Saturday"; else if (day % 7 == 6) DayName = "Sunday"; cout << "The day Number for " << date << "-" << month << " is " << day << " and today is " << DayName << endl; return 0; }
OUTPUT
/* Program for displaying the day number and day name of a year (not leap) after getting month and date as input. Let day-1=Tuesday */ #include<iostream> using namespace std; int main() { int month, date, day; do { cout << "Enter Month (1-12)?\t"; cin >> month; } while (month > 12 || month < 1); if (month == 1) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = date; } else if (month == 2) { do { cout << "Enter Date (+ve number less than 28)?\t"; cin >> date; } while (date > 28 || date < 1); day = 31 + date; } else if (month == 3) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 59 + date; } else if (month == 4) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 90 + date; } else if (month == 5) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 120 + date; } else if (month == 6) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 30 || date < 1); day = 151 + date; } else if (month == 7) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 181 + date; } else if (month == 8) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 212 + date; } else if (month == 9) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 243 + date; } else if (month == 10) { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 273 + date; } else if (month == 11) { do { cout << "Enter Date (+ve number less than 30)?\t"; cin >> date; } while (date > 30 || date < 1); day = 304 + date; } else { do { cout << "Enter Date (+ve number less than 31)?\t"; cin >> date; } while (date > 31 || date < 1); day = 334 + date; } cout << "The day Number for " << date << "-" << month << " is " << day; if (day % 7 == 0) cout << " and today is Monday" << endl; else if (day % 7 == 1) cout << " and today is Tuesday" << endl; else if (day % 7 == 2) cout << " and today is Wednesday" << endl; else if (day % 7 == 3) cout << " and today is Thursday" << endl; else if (day % 7 == 4) cout << " and today is Friday" << endl; else if (day % 7 == 5) cout << " and today is Saturday" << endl; else cout << " and today is Sunday" << endl; return 0; }
OUTPUT
No comments:
Post a Comment