Question

Complete the following program in C; Have the user input the current month and return the...

Complete the following program in C; Have the user input the current month and return the previous month.

E.g. input -> 3, returns 2
input -> 1, returns 12

#include <stdio.h>
#include <stdlib.h>

/* Write a function called previous_month that returns the previous month.
start with the following code */


enum month {jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec};
typedef enum month month;

int main() {

            return0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>

/* Write a function called previous_month that returns the previous month.
start with the following code */


enum month {
    jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
};
typedef enum month month;

enum month previous_month(enum month m) {
    if (m == jan)
        return dec;
    else if (m == feb)
        return jan;
    else if (m == mar)
        return feb;
    else if (m == apr)
        return mar;
    else if (m == may)
        return apr;
    else if (m == jun)
        return may;
    else if (m == jul)
        return jun;
    else if (m == aug)
        return jul;
    else if (m == sep)
        return aug;
    else if (m == oct)
        return sep;
    else if (m == nov)
        return oct;
    else
        return nov;
}

int main() {
    enum month m;
    printf("Enter a month(1-12): ");
    scanf("%d", &m);
    printf("%d\n", previous_month(m));
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Complete the following program in C; Have the user input the current month and return the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • If there are any seasonality or relationship between the price and the US oil price? How...

    If there are any seasonality or relationship between the price and the US oil price? How to analyze? Jan-10 2.769 Jan-11 3.148 Jan-12 3.44 Jan-13 3.391 Jan-14 3.392 Feb-10 2.699 Feb-11 3.264 Feb-12 3.64 Feb-13 3.736 Feb-14 3.434 Mar-10 2.824 Mar-11 3.615 Mar-12 3.907 Mar-13 3.779 Mar-14 3.606 Apr-10 2.9 Apr-11 3.852 Apr-12 3.958 Apr-13 3.638 Apr-14 3.735 May-10 2.89 May-11 3.96 May-12 3.791 May-13 3.675 May-14 3.75 Jun-10 2.785 Jun-11 3.735 Jun-12 3.596 Jun-13 3.689 Jun-14 3.766 Jul-10 2.782...

  • Moving average (MA) Calculate the sales using 2, 3, 4, 5, and 6 month moving average...

    Moving average (MA) Calculate the sales using 2, 3, 4, 5, and 6 month moving average values. Forecast and plot the upcoming period’s sales using the moving average series that fits best. Explain why you chose that particular MA. Why is it inadvisable to use the Moving Average approach to forecast far into the future? Month Sale Month Sale Month Sale Oct-12 13.30 Oct-13 24.01 Oct-14 50.56 Nov-12 1.70 Nov-13 32.67 Nov-14 60.06 Dec-12 11.44 Dec-13 23.19 Dec-14 61.73 Jan-13...

  • Given the following history, use a three-quarter moving average to forecast the demand for the third...

    Given the following history, use a three-quarter moving average to forecast the demand for the third quarter of this year. Note, the 1st quarter is Jan, Feb, and Mar; 2nd quarter Apr, May, Jun; 3rd quarter Jul, Aug, Sep; and 4th quarter Oct, Nov, Dec. JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC Last year 170 200 210 240 250 270 225 215 215 275 280 300 This year 205 210 140 255 245 220 Forecast...

  • calculate the monthly time-weighted and money weighted returns for shareholders in the ADKSX with using excel....

    calculate the monthly time-weighted and money weighted returns for shareholders in the ADKSX with using excel. In a text box nearby, comment on whether investors’ trading decisions have created value. Month ADKSX Return (%) ADKSX Cash Flow ($) Nov-09 3.49 -$10,648,393 Dec-09 6.93 -$618,800 Jan-10 -2.05 $940,820 Feb-10 5.74 -$2,484,437 Mar-10 5.19 -$3,699,836 Apr-10 5.48 -$1,379,757 May-10 -4.68 $2,145,936 Jun-10 -6.31 -$2,953,884 Jul-10 5.9 -$4,160,472 Aug-10 -5.18 $1,096,304 Sep-10 8.61 -$5,571,657 Oct-10 4.5 -$669,464 Nov-10 2.77 -$3,145,367 Dec-10 9.16 -$6,162,018...

  • IN C++ In a previous assignment you wrote pseudo code for the calculation of the days...

    IN C++ In a previous assignment you wrote pseudo code for the calculation of the days into a year given the date. Write a function that returns an int. It takes three parameters , all int(s), int DaysIntoYear ( int Year, int Month, int day); The return value is the number of days in the year from January 1 to the specified date.   Year is included so you can determine if this is a leap year ( see below).   If...

  • Calculate the sample correlation coefficient rxy. Calculate the value of the test statistic. Date Energy Healthcare...

    Calculate the sample correlation coefficient rxy. Calculate the value of the test statistic. Date Energy Healthcare Jan-10 -4.87 -0.15 Feb-10 1.8 0.53 Mar-10 2.26 1.41 Apr-10 3.03 -3.75 May-10 -11.5 -5.12 Jun-10 -5.67 -0.52 Jul-10 8.73 1.49 Aug-10 -5.99 -0.97 Sep-10 10.15 8.24 Oct-10 3.89 2.28 Nov-10 2.85 -2.52 Dec-10 5.55 1.4 Jan-11 6.6 1.55 Feb-11 5.7 3.04 Mar-11 1.32 1.22 Apr-11 1.64 5.89 May-11 -4.06 2.62 Jun-11 -2.08 -0.55 Jul-11 1.14 -2.64 Aug-11 -10.41 -2.8 Sep-11 -15.06 -4.17 Oct-11...

  • The human resources department needs to forecast the number of employees at a site. The data...

    The human resources department needs to forecast the number of employees at a site. The data for several months is supplied below. Be careful since the data is listed beginning with the most recent. The forecasting method to be used here is the 7 month moving average. Please round your forecast to the nearest whole number Nov 2019: 956 Oct 2019: 1014 Sep 2019: 1009 Aug 2019: 963 Jul 2019: 966 Jun 2019: 1024 May 2019: 1045||Apr 2019: 1047 Mar...

  • Consider five years of monthly sales data for a company in the attached file (Q5.xlsx). a) Foreca...

    Consider five years of monthly sales data for a company in the attached file (Q5.xlsx). a) Forecast monthly sales for the next year (2020). (10 marks) b) Discuss whether a simple exponential smoothing model works well with this data or not. (5 m 7 9 Month Sales 747 Feb-14 697 Mar-14 1014 Jan-14 Ap4 1126 May-14 1105 Jun-14 1450 Jul-14 1633 Aug-14 1711 Sep-14 1307 Oct-1223 Nov-14 9T5 Dec-14S53 4J-15 1024 Feb-15928 Mar-151442 7Apr-151371 May-15 1536 Ju15 2004 Jul-15 1854...

  • Delta IBM Jan-83 0.04 0.027 Feb-83 0.027 0.01 Mar-83 -0.016 0.028 Apr-83 -0.043 0.15 May-83 -0.045...

    Delta IBM Jan-83 0.04 0.027 Feb-83 0.027 0.01 Mar-83 -0.016 0.028 Apr-83 -0.043 0.15 May-83 -0.045 -0.041 Jun-83 0.012 0.081 Jul-83 -0.259 0.001 Aug-83 0.08 0.001 Sep-83 0.041 0.062 Oct-83 0.039 -0.001 Nov-83 0.12 -0.066 Dec-83 -0.028 0.039 Jan-84 -0.013 -0.065 Feb-84 -0.117 -0.026 Mar-84 0.065 0.034 Apr-84 -0.085 -0.002 May-84 -0.07 -0.044 Jun-84 -0.012 -0.019 Jul-84 0.045 0.047 Aug-84 0.04 0.127 Sep-84 0.008 0.004 Oct-84 0.161 0.012 Nov-84 -0.026 -0.023 Dec-84 0.156 0.011 Jan-85 -0.01 0.108 Feb-85 0.087 -0.009...

  • Use the data table to estimate the alpha of Nike and HP Inc. ​stock, expressed as​...

    Use the data table to estimate the alpha of Nike and HP Inc. ​stock, expressed as​ % per month. Monthly Returns Date Nike HP Inc. S&P 500 Jan-11 -3.442% 8.527% 2.330% Feb-11 7.941% -4.509% 3.474% Mar-11 -14.624% -5.913% -0.005% Apr-11 8.745% -1.465% 2.896% May-11 2.587% -7.406% -1.121% Jun-11 6.915% -2.301% -1.706% Jul-11 0.189% -3.379% -2.000% Aug-11 -3.882% -25.988% -5.498% Sep-11 -0.958% -13.292% -6.910% Oct-11 12.677% 18.530% 10.915% Nov-11 -0.176% 5.036% -0.406% Dec-11 0.572% -7.406% 1.024% Jan-12 7.907% 8.618% 4.637% Feb-12...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT