Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string findMonth(int x) {
- if (x >= 1 && x <= 31)
- return "jan";
- else if (x >= 32 && x <= 59)
- return "feb";
- else if (x >= 60 && x <= 90)
- return "mar";
- else if (x >= 91 && x <= 120)
- return "apr";
- else if (x >= 121 && x <= 151)
- return "may";
- else if (x >= 152 && x <= 181)
- return "jun";
- else if (x >= 182 && x <= 212)
- return "jul";
- else if (x >= 213 && x <= 243)
- return "aug";
- else if (x >= 244 && x <= 273)
- return "sep";
- else if (x >= 274 && x <= 304)
- return "oct";
- else if (x >= 305 && x <= 334)
- return "nov";
- else if (x >= 335 && x <= 365)
- return "dec";
- else if (x > 365 || x < 1)
- return "inv";
- }
- int findDay(int x) {
- int y = 0;
- if (x > 365)
- x = x - 365;
- if (x > 0 && x < 32)
- return x;
- else if (x >= 32 && x <= 59) {
- y = x - 31;
- return y;
- }
- else if (x >= 60 && x <= 90) {
- y = x - 59;
- return y;
- }
- else if (x >= 91 && x <= 120) {
- y = x - 90;
- return y;
- }
- else if (x >= 121 && x <= 151) {
- y = x - 120;
- return y;
- }
- else if (x >= 152 && x <= 181) {
- y = x - 151;
- return y;
- }
- else if (x >= 182 && x <= 212) {
- y = x - 181;
- return y;
- }
- else if (x >= 213 && x <= 243) {
- y = x - 212;
- return y;
- }
- else if (x >= 244 && x <= 273) {
- y = x - 243;
- return y;
- }
- else if (x >= 274 && x <= 304) {
- y = x - 273;
- return y;
- }
- else if (x >= 305 && x <= 334) {
- y = x - 304;
- return y;
- }
- else if (x >= 335 && x <= 365) {
- y = x - 334;
- return y;
- }
- else if (x < 1 || x > 365)
- return 0;
- }
- int main() {
- int input = 1, day = 0, ya = 0;
- string mo;
- cout << "Please enter a day of the year (0 to exit): ";
- cin >> input;
- cout << input << endl;
- while (input != 0) {
- if (input > 365) {
- ya = (double)input / 365;
- cout << ya << " year" << endl;
- //mo = findMonth (input - (365*ya));
- //day = findDay (input - (365*ya));
- //cout << mo << " " << day << endl;
- }
- else {
- mo = findMonth(input);
- day = findDay(input);
- cout << mo << " " << day << endl;
- }
- cout << "Please enter a day of the year (0 to exit): ";
- cin >> input;
- cout << input << endl;
- }
- cout << "Thanks for playing!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement