Hi everyone, I need your help to write this C++ function. Every month corresponds to a number. I need the function to return the value for the month. For example, user input month as MM (i.e. aug is 08) jan returns 0, feb 3, mar returns 3 and so on. how do I do this? This is what I've got so far: Function Prototype: int monthValue(int month) //returns a certain value for every month Function Definition: int monthValue(month, year) { } What should I do in the function definition/body? Here is the full list of values int jan(0), , feb(3), mar(3), apr(6), may(1), jun(4), jul(6), aug(2), sep(5), oct(0), nov(3), dec(5);
There are lots of ways to do it. Here's one. Code: int monthValue(int month,int year) { if (month==2 && is_leap_year(year)) { // you didn't say what value to return here // drop this block if leap years are handled elsewhere // but the fact that year is passed in suggests they're not } else return month["0033614625035"]-'0'; }